Camila Waz 发布于
2019-12-09 17:19:48

js对象转字符串JSON.stringify()和字符串转对象JSON.parse()函数

js对象转字符串JSON.stringify()和字符串转对象JSON.parse()函数


1、对象转字符串JSON.stringify():

var object=[
{'id':1,'title':"aaa"},
{'id':1,'title':"aaa"},
{'id':1,'title':"aaa"},
]
console.log(JSON.stringify(object));

输出结果:[{"id":1,"title":"aaa"},{"id":1,"title":"aaa"},{"id":1,"title":"aaa"}]


2字符串对象JSON.parse():

var string='[{"id":1,"title":"aaa"},{"id":1,"title":"aaa"},{"id":1,"title":"aaa"}]'
console.log(JSON.parse(string))
输出结果:[
    {"id":1,"title":"aaa"},
    {"id":1,"title":"aaa"},
    {"id":1,"title":"aaa"}
]
当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2019-12-09/507.html
最后生成于 2020-10-09 16:47:51