[英]extracting fields from JSON output using python
使用 Python,如何将字段 RestartRowID 提取到变量中?:
{
"emp": [
{
"id": "",
"company": "y",
"address": "y",
"mobile no": 0,
"name": 0
}
],
"RestartRowID": "0x0000000000133a09"
}
就像是:
id = emp["RestartRowID"]
print (id)
谢谢..
将 json 数据转换为字典
data_dict=json.loads(<jsondata>)
您可以使用 data_dict['RestartRowID'] 获得所需的答案
像这样的东西:
>>> import json
>>> a = '''{
... "emp": [
... {
...
... "id": "",
... "company": "y",
... "address": "y",
... "mobile no": 0,
... "name": 0
... }
... ],
... "RestartRowID": "0x0000000000133a09"
... }'''
>>> data = json.loads(a)
>>> data['RestartRowID']
u'0x0000000000133a09'
>>>
emp
和RestartRowID
处于同一级别,因此您应该从另一个中提取一个。
data = {
"emp": [
{
"id": "",
"company": "y",
"address": "y",
"mobile no": 0,
"name": 0
}
],
"RestartRowID": "0x0000000000133a09"
}
Output:
In [264]: id = data["RestartRowID"]
In [265]: id
Out[265]: '0x0000000000133a09'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.