【发布时间】:2011-07-21 09:27:55
【问题描述】:
我有以下 json:
{
"slate" : {
"id" : {
"type" : "integer"
},
"name" : {
"type" : "string"
},
"code" : {
"type" : "integer",
"fk" : "banned.id"
}
},
"banned" : {
"id" : {
"type" : "integer"
},
"domain" : {
"type" : "string"
}
}
}
我想找出最佳解码方式,以便对其进行易于浏览的 python 对象表示。
我试过了:
import json
jstr = #### my json code above ####
obj = json.JSONDecoder().decode(jstr)
for o in obj:
for t in o:
print (o)
但我明白了:
f
s
l
a
t
e
b
a
n
n
e
d
我不明白这是怎么回事。理想的情况是一棵树(甚至是一个以树的方式组织的列表),我可以以某种方式浏览它:
for table in myList:
for field in table:
print (field("type"))
print (field("fk"))
Python 的内置 JSON API 范围是否足以达到这一预期?
【问题讨论】:
标签: python json python-3.x