search

Home  >  Q&A  >  body text

Python解析服务器返回的json格式数据

RT,服务器返回的json格式的数据有一些地方与python不一样,如"a":true, 用python自带的json模块进行解析总是出错,请问python一般怎么解析这些数据

巴扎黑巴扎黑2784 days ago700

reply all(3)I'll reply

  • 黄舟

    黄舟2017-04-17 13:03:54

    Use spidermonkey or v8’s python binding to do JSON.stringify on the incoming data as a js object.

    You can also go through node.js through subprocess.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:03:54

    You can use JSON.stringfy to pre-process the data on the front end as described by yj.lee, or when using python to parse, pass a preprocessing function (json.decoder) like the cls parameter of json.loads() to Data preprocessing.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 13:03:54

    First of all, you need to make sure your json format is correct. Generally, python’s json will not go wrong. After all, we are not Inspur front-end people. The main cause of the problem may be that the json format is incorrect.

    It is recommended to post it in json format for a look.

    If it is the above "a":true you need to do this

    >>> import json
    >>> json.loads(json.dumps('"a":true'))
    u'"a":true'
    

    reply
    0
  • Cancelreply