使用Python,如何将RestartRowID字段提取为变量?
{
"emp": [
{
"id": "",
"company": "y",
"address": "y",
"mobile no": 0,
"name": 0
}
],
"RestartRowID": "0x0000000000133a09"
}
类似:
id = emp["RestartRowID"]
print (id)
谢谢..
答案 0 :(得分:0)
将json数据转换为字典
data_dict=json.loads(<jsondata>)
您可以使用data_dict ['RestartRowID']
来获得所需的答案。答案 1 :(得分:0)
类似这样的东西:
>>> import json
>>> a = '''{
... "emp": [
... {
...
... "id": "",
... "company": "y",
... "address": "y",
... "mobile no": 0,
... "name": 0
... }
... ],
... "RestartRowID": "0x0000000000133a09"
... }'''
>>> data = json.loads(a)
>>> data['RestartRowID']
u'0x0000000000133a09'
>>>
答案 2 :(得分:0)
emp
和RestartRowID
处于同一级别,因此您应该从另一个中提取一个。
data = {
"emp": [
{
"id": "",
"company": "y",
"address": "y",
"mobile no": 0,
"name": 0
}
],
"RestartRowID": "0x0000000000133a09"
}
输出:
In [264]: id = data["RestartRowID"]
In [265]: id
Out[265]: '0x0000000000133a09'