Converting the original object javascript python dictionary

Reproduced

https://cloud.tencent.com/developer/ask/175357

Problem Description

Some websites data is in a format js file a return does not comply with the format in Python json data. That we can not use json.loads be deserialized.

Here Insert Picture Description

Regular

demjson

import demjson

# from
js_obj = '{x:1, y:2, z:3}'

# to
py_obj = demjson.decode(js_obj)

jsonnet

import json, _jsonnet

# from
js_obj = '{x:1, y:2, z:3}'

# to
py_obj = json.loads(_jsonnet.evaluate_snippet('snippet', js_obj))

ast

import ast

# from
js_obj = "{'x':1, 'y':2, 'z':3}"

# to
py_obj = ast.literal_eval(js_obj)
Published 291 original articles · won praise 104 · views 410 000 +

Guess you like

Origin blog.csdn.net/Enjolras_fuu/article/details/104288218