给出以下代码:
import json
foo = '{"root":"cfb-score","children":{"gamecode":{"attribute":"global-id"},"gamestate":{"attribute":"status-id","attribute":"status","attribute":"quarter","attribute":"minutes","attribute":"seconds","attribute":"team-possession-id","attribute":"yards-from-goal","attribute":"down","attribute":"distance","attribute":"segment-number","attribute":"active-state"},"gametype":{"attribute":"type","attribute":"detail"},"stadium":{"attribute":"name","attribute":"city","attribute":"state"},"visiting-team:team-name":{"attribute":"alias"},"visiting-team:team-code":{"attribute":"global-id"},"visiting-team:team-rank":{"attribute":"rank"}}}'
bar = json.loads(foo)
print json.dumps(bar)
在使用 json.loads 或 json.load 时,所有最低级别的“子级”都被截断(或者更有可能被覆盖),除了最后一个。为什么?json 格式正确,可以在此处验证:http: //json.parser.online.fr/
一大块输入:
"children" : {
"gamecode" : {
"attribute" : "global-id"
},
"gamestate" : {
"attribute" : "status-id",
"attribute" : "status",
"attribute" : "quarter",
"attribute" : "minutes",
"attribute" : "seconds",
"attribute" : "team-possession-id",
"attribute" : "yards-from-goal",
"attribute" : "down",
"attribute" : "distance",
"attribute" : "segment-number",
"attribute" : "active-state"
},
转向这块输出:
"children" : {
"gamecode" : {
"attribute" : "global-id"
},
"gamestate" : {
"attribute" : "active-state"
},