python解读json超内存_python - 读取包含Unicode数据的JSON文件 - 堆栈内存溢出

这是我的JSON文件的内容

cat ./myfile.json

{u'Records': [{u'eventVersion': u'2.0', }]}

如何读取此JSON文件?

我尝试使用以下代码读取文件,

def Read_json_file(jsonFile):

jsonDy = {}

if os.path.exists(jsonFile):

with open(jsonFile, 'rt') as fin:

jsonDy = json.load(fin)

else:

print("JSON file not available ->",

jsonFile)

sys.exit(1)

print("jsonDy -> ", jsonDy)

但是出现以下错误,

Traceback (most recent call last):

File "a.py", line 125, in

Main()

File "a.py", line 18, in Main

content = Read_json_file(eventFile)

File "a.py", line 44, in Read_json_file

jsonDy = json.load(fin)

File "/usr/lib64/python2.7/json/__init__.py", line 290, in load

**kw)

File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads

return _default_decoder.decode(s)

File "/usr/lib64/python2.7/json/decoder.py", line 365, in decode

obj, end = self.raw_decode(s, idx=_w(s, 0).end())

File "/usr/lib64/python2.7/json/decoder.py", line 381, in raw_decode

obj, end = self.scan_once(s, idx)

ValueError: Expecting property name: line 1 column 2 (char 1)

我的理解是, u'代表unicode表示法,但不确定如何读取此文件

PS :我正在使用Python 2.7

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值