gpt4 book ai didi

python - 如何在没有子数据的情况下获取值(value)?

转载 作者:太空宇宙 更新时间:2023-11-04 11:19:59 24 4
gpt4 key购买 nike

尝试从我的 json 中获取这些数据:

O2FDSFDSN47U-BFSDFSDWO3-TTFSDFS245H
OIBKDFSDFS2B-K6A2FSDFSDO-2GPFSDFSNES
OSZZEE-FDSDQUNAZ-OHDSQDQS2NDS

使用 print(data['result']['open']) :但返回 id 之后的所有数据。

这些id还在动,我猜不出来。使用正则表达式似乎不是一个好主意

没有别的,但是当使用我的 python 解析器时,我总是得到子数据。

{
"error": [],
"result": {
"open": {
"O2FDSFDSN47U-BFSDFSDWO3-TTFSDFS245H": {
"refid": null,
"userref": 0,
"status": "open",
"starttm": 0,
"expiretm": 0,
"descr": {
"ordertype": "limit",
"price": "3",
"price2": "0",
"leverage": "none",
"close": ""
},
"vol": "1.00000000",
"vol_exec": "0.00000000",
"cost": "0.00000",
"fee": "0.00000",
"price": "0.00000",
"stopprice": "0.00000",
"limitprice": "0.00000",
"misc": "",
"oflags": "fcib"
},
"OIBKDFSDFS2B-K6A2FSDFSDO-2GPFSDFSNES": {
"refid": null,
"userref": 0,
"status": "open",
"starttm": 0,
"expiretm": 0,
"descr": {
"ordertype": "limit",
"price": "1.5",
"price2": "0",
"leverage": "none",
"close": ""
},
"vol": "2.00000000",
"vol_exec": "0.00000000",
"cost": "0.00000",
"fee": "0.00000",
"price": "0.00000",
"stopprice": "0.00000",
"limitprice": "0.00000",
"misc": "",
"oflags": "fciq"
},
"OSZZEE-FDSDQUNAZ-OHDSQDQS2NDS": {
"refid": null,
"userref": 0,
"status": "open",
"starttm": 0,
"expiretm": 0,
"descr": {
"ordertype": "limit",
"price": "9",
"price2": "0",
"leverage": "none",
"close": ""
},
"vol": "1.00000000",
"vol_exec": "0.00000000",
"cost": "0.00000",
"fee": "0.00000",
"price": "0.00000",
"stopprice": "0.00000",
"limitprice": "0.00000",
"misc": "",
"oflags": "fciq"
}
}
}
}

如何一举拿下论文?

最佳答案

import json
s = '''{
"error": [],
"result": {
"open": {
"O2FDSFDSN47U-BFSDFSDWO3-TTFSDFS245H": {
"refid": null,
"userref": 0,
"status": "open",
"starttm": 0,
"expiretm": 0,
"descr": {
"ordertype": "limit",
"price": "3",
"price2": "0",
"leverage": "none",
"close": ""
},
"vol": "1.00000000",
"vol_exec": "0.00000000",
"cost": "0.00000",
"fee": "0.00000",
"price": "0.00000",
"stopprice": "0.00000",
"limitprice": "0.00000",
"misc": "",
"oflags": "fcib"
},
"OIBKDFSDFS2B-K6A2FSDFSDO-2GPFSDFSNES": {
"refid": null,
"userref": 0,
"status": "open",
"starttm": 0,
"expiretm": 0,
"descr": {
"ordertype": "limit",
"price": "1.5",
"price2": "0",
"leverage": "none",
"close": ""
},
"vol": "2.00000000",
"vol_exec": "0.00000000",
"cost": "0.00000",
"fee": "0.00000",
"price": "0.00000",
"stopprice": "0.00000",
"limitprice": "0.00000",
"misc": "",
"oflags": "fciq"
},
"OSZZEE-FDSDQUNAZ-OHDSQDQS2NDS": {
"refid": null,
"userref": 0,
"status": "open",
"starttm": 0,
"expiretm": 0,
"descr": {
"ordertype": "limit",
"price": "9",
"price2": "0",
"leverage": "none",
"close": ""
},
"vol": "1.00000000",
"vol_exec": "0.00000000",
"cost": "0.00000",
"fee": "0.00000",
"price": "0.00000",
"stopprice": "0.00000",
"limitprice": "0.00000",
"misc": "",
"oflags": "fciq"
}
}
}
}'''

data = json.loads(s)

>>> data['result']['open'].keys()
dict_keys(['O2FDSFDSN47U-BFSDFSDWO3-TTFSDFS245H', 'OIBKDFSDFS2B-K6A2FSDFSDO-2GPFSDFSNES', 'OSZZEE-FDSDQUNAZ-OHDSQDQS2NDS'])
>>>

关于python - 如何在没有子数据的情况下获取值(value)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56213235/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com