python操作JSON

版权声明:本文为博主原创文章,未经允许也可以任意转载。http://huyouxiao.com https://blog.csdn.net/fudaxing/article/details/88849969
  • python 读取json用 json.loads(stringOfJsonData) python
  • 将dictionary转换称json用 json.dumps(pythonValue)
Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> stringOfJsonData = '{"name": "Zophie", "isCat": true, "miceCaught": 0, "felineIQ": null}'
>>> import json
>>> jsonDataAsPythonValue = json.loads(stringOfJsonData)
>>> jsonDataAsPythonValue
{'miceCaught': 0, 'name': 'Zophie', 'felineIQ': None, 'isCat': True}
>>> pythonValue = {'isCat': True, 'miceCaught': 0, 'name': 'Zophie', 'felineIQ': None}
>>> jsonData = json.dumps(pythonValue)
>>> jsonData
'{"miceCaught": 0, "isCat": true, "felineIQ": null, "name": "Zophie"}'
>>> 

猜你喜欢

转载自blog.csdn.net/fudaxing/article/details/88849969
今日推荐