如何获取 JSON 数据节点中的元素数量?
JSON:
{
"result":[
{
"run":[
{
"action":"stop"
},
{
"action":"start"
},
{
"action":"start"
}
],
"find":true
}
]
}
我需要从节点 data['result'][0]['run']
获取元素的数量。它应该是 3,但我在 Python 中找不到如何做到这一点。
最佳答案
import json
json_data = json.dumps({
"result":[
{
"run":[
{
"action":"stop"
},
{
"action":"start"
},
{
"action":"start"
}
],
"find": "true"
}
]
})
item_dict = json.loads(json_data)
print len(item_dict['result'][0]['run'])
在字典中转换。
https://stackoverflow.com/questions/27315472/
相关文章:
javascript - 为什么 Google 在前面加上 while(1);到他们的 JSON 响
javascript - jQuery AJAX 轮询 JSON 响应,基于 AJAX 结果或 JS
json - 在 Go : required field? 中解码 json
ruby-on-rails - 无法在 Ubuntu 上使用 ruby 2.2.3 安装 jso
json - 当使用 Spring MVC for REST 时,如何让 Jackson 漂亮地打印
javascript - 将返回的 JSON 对象属性转换为(较低的第一个)camelCase