我从某处获取json字符串化,并尝试通过 json.loads()将其转换为对象。...我的字符串是:
mystring = "{\"browse\":{\"postList\":{\"p\":1,\"ce\":true,\"token\":\"2C_AmcmNf\",\"c\":\"100\",\"p4\":null,\"p1\":null,\"c4\":null,\"d\":3,\"ic\":4,\"lm\":1549382114,\"c2\":137,\"p2\":5,\"c1\":125,\"hc\":false,\"c3\":null,\"p3\":null,\"image\":\"https:\u002F\u002Fs100u002Fstatic\u002Fthumbnails\u002F1549382114\u002F2C_Am\"cmNf.jpg\"}}}";
运行此命令时
aaaa = regex.sub(r'(\\")', '\"', mystring) # remove extra \ from string
xx = JSON.loads(aaaa, encoding='utf8')
遇到此错误:
载入中的文件“ /usr/lib/python3.4/json/init.py”,第318行
返回_default_decoder.decode(s)
解码中的文件“ /usr/lib/python3.4/json/decoder.py”,第343行
obj,end = self.raw_decode(s,idx = _w(s,0).end())
raw_decode中的文件“ /usr/lib/python3.4/json/decoder.py”,第359行
obj,end = self.scan_once(s,idx)
ValueError:预期为','分隔符:第1行第7249列(字符7248)
我该怎么办?在标准模式下解决此问题
我想听一堂课,所以我可以说xx[browse]
!!!!
答案 0 :(得分:0)
import json
data = json.dumps(mystring)
print(json.loads(data))
>>>{"browse":{"postList":{"p":1,"ce":true,"token":"2C_AmcmNf","c":"100","p4":null,"p1":null,"c4":null,"d":3,"ic":4,"lm":1549382114,"c2":137,"p2":5,"c1":125,"hc":false,"c3":null,"p3":null,"image":"https:\u002F\u002Fs100u002Fstatic\u002Fthumbnails\u002F1549382114\u002F2C_Am"cmNf.jpg"}}}