我有以下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的范围是否足够宽,可以达到这个期望?
我想应该是你创建了一个解码器,但永远不要告诉它^{} 。
使用:
试试看
而不是
您似乎需要帮助迭代返回的对象,以及解码JSON。
相关问题 更多 >
编程相关推荐