JSON return [关闭]

pexxcrt2  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(67)

已关闭。此问题需要details or clarity。目前不接受回答。
**要改进此问题吗?**通过editing this post添加详细信息并阐明问题。

21天前关闭
Improve this question
我有一个通过curl的JSON调用的返回值,它返回:

{
    'result': {
        'today_runtime': 830,
        'month_runtime': 39991,
        'today_energy': 1293,
        'month_energy': 55326,
        'local_time': '2022-11-27 13:50:54',
        'electricity_charge': \[0, 0, 0\],
        'current_power': 93860
    },
    'error_code': 0
}

字符串
我需要来自内括号部分中的键值对的值,我知道如何在不使用以下命令的情况下提取它们:

{'result':


, 'error_code': 0}


因为我已经手动将它们截断,并在提取值时获得预期的结果。

uemypmqf

uemypmqf1#

{
    'result': {
        'today_runtime': 830,
        'month_runtime': 39991,
        'today_energy': 1293,
        'month_energy': 55326,
        'local_time': '2022-11-27 13:50:54',
        'electricity_charge': \[0, 0, 0\],
        'current_power': 93860
    },
    'error_code': 0
}

字符串
这是一个字典,它有两个键:“result”和“error_code”。
“result”键的值也是一个字典,有七个键。
(The但是“electricity_charge”键很奇怪。为什么会有反斜杠\[\]?我想这是你的格式怪癖。)
假设你把这个字典赋给了一个名为data的变量,你会像这样访问信息:

data['result']['today_runtime']
data['result']['month_runtime']
...
data['result']['current_power']
data['error_code']


这些都是非常直接的字典语法,一点也不“废话”。

相关问题