import json
# some JSON:
x = '{ "name":"John", "age":30, "city":"New York"}'
# parse x:
y = json.loads(x)
# the result is a Python dictionary:
print(y["age"])
**
,然后您可以调用y ['键'] =使用数据的值 在这里,y ['name'] =“约翰”
If you're looking to convert JSON (essentially text) to a python dict , then I would suggest you use this:
**
import json
# some JSON:
x = '{ "name":"John", "age":30, "city":"New York"}'
# parse x:
y = json.loads(x)
# the result is a Python dictionary:
print(y["age"])
**
then you can call y['keys'] = values to use data here , y['name'] = "John"
发布评论
评论(1)
如果您想将json(本质上是文本)转换为python dict,那么我建议您使用以下方式:
**
**
,然后您可以调用y ['键'] =使用数据的值
在这里,y ['name'] =“约翰”
If you're looking to convert JSON (essentially text) to a python dict , then I would suggest you use this:
**
**
then you can call y['keys'] = values to use data
here , y['name'] = "John"