js中json项对象转字符串

原始json:
   consot  values = {"id":"1294943322932195329","variables":{"name":"俞宝山","deptName":"科技部","time":["2020-07-22","2020-09-03"],"type":"4","remark":"备注"}}

转换方式:

for (let key in values) {

    if(typeof(values[key]) ==='object' ){

        values[key] = JSON.stringify(values[key])

    }

}

转换后:

{"id":"1294943322932195329","variables":{"name":"俞宝山","deptName":"科技部","time":"[\"2020-07-22\",\"2020-09-03\"]","type":"4","remark":"备注"}}

你可能感兴趣的:(js中json项对象转字符串)