python json json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes
来源:互联网 发布:淘宝商城的商业模式 编辑:程序博客网 时间:2024/05/03 14:50
>>> import json>>> test="{'data':'123'}">>> result=json.loads(test)Traceback (most recent call last): File "<stdin>", line 1, in <module> File "d:\Anaconda3\lib\json\__init__.py", line 319, in loads return _default_decoder.decode(s) File "d:\Anaconda3\lib\json\decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "d:\Anaconda3\lib\json\decoder.py", line 355, in raw_decode obj, end = self.scan_once(s, idx)json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
原因在于:字符串里用单引号来标识字符。
解决办法如下:将字符串里的单引号替换成双引号
>>> import re>>> test=re.sub('\'','\"',test)>>> result=json.loads(test)>>> result['data']'123'
对于带u'的字符串,u也要去掉:
>>> c=f.read()>>> c"{u'meta': {u'code': 200, u'requestId': u'5815f6739fb6b77494061e19'}, u'response': {u'tips': {u'count': 0, u'items': []}}}">>> d=re.sub("u'","\"",c)>>> d'{"meta\': {"code\': 200, "requestId\': "5815f6739fb6b77494061e19\'}, "response\': {"tips\': {"count\': 0, "items\': []}}}'>>> d=re.sub("'","\"",d)>>> d'{"meta": {"code": 200, "requestId": "5815f6739fb6b77494061e19"}, "response": {"tips": {"count": 0, "items": []}}}'>>> json.loads(d){'response': {'tips': {'items': [], 'count': 0}}, 'meta': {'requestId': '5815f6739fb6b77494061e19', 'code': 200}}>>>
0 0
- python json json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes
- Python解析json之ValueError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
- Python 字符串转python json.decoder.JSONDecodeError
- python解析json报错ValueError: Expecting property name: line 1 column 2 (char 1)
- python JSON ValueError: Expecting property name: line 1 column 2 (char 1)
- [解决办法]Python中使用json.loads解码字符串时出错:ValueError: Expecting property name: line 1 column 2 (char 1)
- Python中使用json.loads解码字符串时出错:ValueError: Expecting property name: line 1 column 1 (char 1)
- [解决办法]Python中使用json.loads解码字符串时出错:ValueError: Expecting property name: line 1 column 2 (char 1)
- [解决办法]Python中使用json.loads解码字符串时出错:ValueError: Expecting property name: line 1 column 2 (char 1)
- The table name must be enclosed in double quotation marks or sqare bracket while accessing EXCEL by
- SyntaxError: JSON.parse: expected property name or '}'
- java web 用ajax封装json报错Could not read JSON: Unrecognized token 'name': was expecting 'null', 'true',
- was expecting double-quote to start field name错误
- DB Query Analyzer 5.03 is distributed, EXCEL table name will be enclosed in square bracket
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- hive expecting Identifier near 'table' in table name 报错
- Excel 2 Json For Python In Mac
- net.sf.json.JSONException: java.lang.NoSuchMethodException: Property 'name' has no getter method
- Linux下case报错syntax error near unexpected token `in
- 大搬家 (2016"百度之星" - 测试赛(热身,陈题))
- 安装ubuntukylin后怎样激活root账户
- poj 3067 poj 2481 树状数组变形+对区间排序
- [leetcode] 153. Find Minimum in Rotated Sorted Array
- python json json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes
- {题解}[jzoj3405]【NOIP2013模拟】舞台表演
- java设计模式之——代理模式
- 如何让iOS启动屏停留更久
- 《java入门第一季》之类String类小案例
- android简单应用(一)
- 关于c#调用c++ dll 的一些问题和解决方案
- Android 中的应用组件--Service
- Objective-C 代码块