4_2 json字符串转Python对象
"""json字符串到Python对象""" import json json_str = ‘[{"username": "张三", "age": 18, "country": "china"}, {"username": "lisi", "age": 20, "country": "USA"}]‘ # json字符串到Python对象 persons = json.loads(json_str) print(type(persons)) # <class ‘list‘> for person in persons: print(person) # 从json文件中读取json数据 with open(‘4_1person.json‘, ‘r‘, encoding=‘utf-8‘) as fp: persons = json.load(fp) print(type(persons)) # <class ‘list‘> for person in persons: print(person)
相关推荐
xiaoseyihe 2020-08-11
pythonxuexi 2020-07-30
leoaran 2020-07-21
littie 2020-07-19
zcabcd 2020-07-18
yjsflxiang 2020-07-04
liusarazhang 2020-06-28
银角大王 2020-06-25
leoaran 2020-06-22
liusarazhang 2020-06-14
89411051 2020-06-14
chinademon 2020-06-11
leoaran 2020-06-06
tengyuan 2020-06-03
shengnanonly 2020-06-03
joyjoy0 2020-06-02
xinhao 2020-05-28