Article Directory
1. Demand:
For example, I extracted the JavaScript json string from the js string, and then found a good module. demjson:
But on my computer, I don't know why today, pip installation failed in various ways, but fortunately, I used python to directly install and unzip the package successfully.
2. How to convert js's json to python dictionary
In fact, using this module is very simple.
Install module commands;
pip install demjson
Conversion code:
actually very simple
import demjson
js_json_str = '{x:1, y:2, z:3}'
py_obj = demjson.decode(js_json_str)
print("py_obj", type(py_obj), py_obj)
# py_obj <class 'dict'> {'x': 1, 'y': 2, 'z': 3}