[英]extracting fields from JSON output using python
Using Python, how can I extract the field RestartRowID to a variable?:使用 Python,如何将字段 RestartRowID 提取到变量中?:
{
"emp": [
{
"id": "",
"company": "y",
"address": "y",
"mobile no": 0,
"name": 0
}
],
"RestartRowID": "0x0000000000133a09"
}
something like:就像是:
id = emp["RestartRowID"]
print (id)
Thanks..谢谢..
convert the json data to dictionary将 json 数据转换为字典
data_dict=json.loads(<jsondata>)
You can get your required answer using data_dict['RestartRowID']您可以使用 data_dict['RestartRowID'] 获得所需的答案
Something like this:像这样的东西:
>>> 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
and RestartRowID
are on the same level so you should be extracting one from the other. emp
和RestartRowID
处于同一级别,因此您应该从另一个中提取一个。
data = {
"emp": [
{
"id": "",
"company": "y",
"address": "y",
"mobile no": 0,
"name": 0
}
],
"RestartRowID": "0x0000000000133a09"
}
Output: Output:
In [264]: id = data["RestartRowID"]
In [265]: id
Out[265]: '0x0000000000133a09'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.