北京网站建设方案书百度搜索服务
python JSON模块
JSON模块是python的库,用来import JSON来解析JSON格式的文件中的数据用于python语言分析,即Parse JSON - Convert from JSON to python。
也可以将python中的数据用JSON格式导出来
https://docs.python.org/zh-cn/2.7/library/json.html#module-json
案例:
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"])
案例:
location = json.load(open('supra_location.json',"rb"),object_pairs_hook=OrderedDict)
案例:
import json# a Python object (dict):
x = {"name": "John","age": 30,"city": "New York"
}# convert into JSON:
y = json.dumps(x)# the result is a JSON string:
print(y)
自然使用了JSON格式的数据,分析键值对是最基本的操作,见下
for key, value in location.items()
location = json.load(open('supra_location.json',"rb"),object_pairs_hook=OrderedDict)
for key, value in location.items():tile_name = str(key)print(key: value)
—NED—