Nima
Nima

Reputation: 45

expecting delimiter error converting stringify to json

i get a json stringify from somewhere and try to convert it to a object by json.loads().... my string is :

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\"}}}";

when i run this:

aaaa = regex.sub(r'(\\")', '\"', mystring)  # remove extra \ from string
xx = JSON.loads(aaaa, encoding='utf8')

get this error:
File "/usr/lib/python3.4/json/init.py", line 318, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.4/json/decoder.py", line 359, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Expecting ',' delimiter: line 1 column 7249 (char 7248)



what should i do? to fix this problem in standard mode

i want a class dict so i can say xx[browse] !!!!

Upvotes: 0

Views: 132

Answers (1)

Veera Balla Deva
Veera Balla Deva

Reputation: 788

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"}}}

Upvotes: 0

Related Questions