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"
        }
    ]
}

 

posted @ 2018-12-20 17:55  無玑小姐  阅读(16154)  评论(1编辑  收藏  举报