dumps是将dict转化成str格式,loads是将str转化成dict格式
import json
a={'name':'y','age':29}
b=json.dumps(a)#dict--str
print(b)
print(type(a))
print(type(b))
c=json.loads(b)#str--dict
print(type(c))
//
{"name": "y", "age": 29}
<class 'dict'>
<class 'str'>
<class 'dict'>
JSON.parse() 方法用于将一个 JSON 字符串转换为对象。
JSON.parse(text[, reviver])
text:必需, 一个有效的 JSON 字符串。
reviver: 可选,一个转换结果的函数, 将为对象的每个成员调用此函数
//
<p id="demo"></p>
<script>
var text = '{"employees":[' +
'{"name":"菜鸟教程","site":"http://www.runoob.com" },' +
'{"name":"Google","site":"http://www.Google.com" },' +
'{"name":"Taobao","site":"http://www.taobao.com" }]}';
obj = JSON.parse(text);
document.getElementById("demo").innerHTML =
obj.employees[1].name + " " + obj.employees[1].site;
</script>
//
从 JSON 字符串中创建一个对象
Google http://www.Google.com