无法加载JSON

时间:2017-07-06 13:46:02

标签: python json

我有代码

data = open('wg.json', 'r').read()
data_parsed = json.loads(data)

收到错误:ValueError: No JSON object could be decoded

我的JSON文件是一个放入json文件的python字典:

{"wind_degrees":103, "dew_p": "73 F (23 C)", "wind_kph": 5.8}

2 个答案:

答案 0 :(得分:1)

$ cat wg.json
{"wind_degrees":103, "dew_p": "73 F (23 C)", "wind_kph": 5.8}
$python
>>> import json
>>> data = open('wg.json', 'r').read()
>>> data_parsed = json.loads(data)
>>> data_parsed
{u'wind_degrees': 103, u'wind_kph': 5.8, u'dew_p': u'73 F (23 C)'}
>>>

我无法重现你的问题。你的代码工作正常。

请注意,您可以稍微简化一下代码:

with open('wg.json', 'r') as fp:
    data_parsed = json.load(fp)

答案 1 :(得分:0)

SelectedItem这样做之后你错过"

73 F (23 C)