parse用于从一个字符串中解析出json对象,如
var str = '{"name":"huangxiaojian","age":"23"}'
结果:
JSON.parse(str)
Object
- age: "23"
- name: "huangxiaojian"
- __proto__: Object
stringify()用于从一个对象解析出字符串,如
var a = {a:1,b:2}
结果:
JSON.stringify(a)
"{"a":1,"b":2}"
删除JSON BY KEY
var keyToDelete = "key1";
var myObj: {"test": {"key1": "value", "key2": "value"}}
delete myObj.test.keyToDelete //would not work.
IF the key is number then:
delete myObj.test[keyToDelete];