类似XML,并且更简单。python自己就有json的库,直接用指令抓出来就能存为dictionary。保存一份模板以后拿来改。
import json
data = '''
[
{ "id" : "001",
"x" : "2",
"name" : "Chuck"
} ,
{ "id" : "009",
"x" : "7",
"name" : "Chuck"
}
]'''
info = json.loads(data)
print('User count:', len(info))
for item in info:
print('Name', item['name'])
print('Id', item['id'])
print('Attribute', item['x'])
输出是这样:
User count: 2
Name Chuck
Id 001
Attribute 2
Name Brent
Id 009
Attribute 7