js格式化json字符串和json对象
1,格式化json对象
var json = {"@odata.context":"$metadata#AddTableOne_466281s","value":[{"NAME":"李四","BIRTHDAY":"2018-10-03T11:33:50+08:00","AGE":"0","ID":"111111"}]} JSON.stringify(json, null, "\t")
2,格式化json字符串
var json = "{"@odata.context":"$metadata#AddTableOne_466281s","value":[{"NAME":"李四","BIRTHDAY":"2018-10-03T11:33:50+08:00","AGE":"0","ID":"111111"}]}" json = JSON.parse(json);//将json字符串格式化为json对象 JSON.stringify(json, null, "\t")
结果
{ "@odata.context": "$metadata#AddTableOne_466281s", "value": [ { "NAME": "李四", "BIRTHDAY": "2018-10-03T11:33:50+08:00", "AGE": "0", "ID": "111111" } ] }