【发布时间】:2016-03-11 11:48:25
【问题描述】:
我的 json 文件,嗯,它的一部分看起来像:
[
{
"id": 472,
"name": "אבו גוש",
"engName": "ABU GHOSH"
},
{
"id": 473,
"name": "אבו סנאן",
"engName": "ABU SINAN"
},
{
"id": 1342,
"name": "אבו קורינאת (יישוב)",
"engName": "ABU QUREINAT"
},
]
等等。
我的部分代码看起来像:
with open('israelCities.json') as data_file:
jsonData = json.loads(data_file.read().encode('utf8'))
print(jsonData)
它在第二行失败(jsonData = ....), 我是 python 新手,没有看到任何类似的问题, 任何帮助将不胜感激
谢谢!!
编辑
这两个对我来说很完美:
import json
import urllib.request
url='https://raw.githubusercontent.com/royts/israel-cities/master/israel-cities.json'
data = urllib.request.urlopen(url).read().decode('utf-8')
json.loads(data)
还有这个:
import json
import requests
r = requests.get('https://raw.githubusercontent.com/royts/israel-cities/master/israel-cities.json')
with open('israelCities.json', 'w') as f:
json.dump(r.json(), f)
with open('israelCities.json') as f:
json_data = json.load(f)
谢谢!!
【问题讨论】:
-
失败是什么意思?你得到了什么错误?
-
你好,不知道为什么,我的原帖被删了,pycharm没有错误
标签: python json parsing hebrew