How to parse data in JSON format?

后端 未结 5 1660
梦谈多话
梦谈多话 2020-11-21 07:12

My project is currently receiving a JSON message in python which I need to get bits of information out of. For the purposes of this, let\'s set it to some simple JSON in a s

5条回答
  •  日久生厌
    2020-11-21 07:47

    Sometimes your json is not a string. For example if you are getting a json from a url like this:

    j = urllib2.urlopen('http://site.com/data.json')
    

    you will need to use json.load, not json.loads:

    j_obj = json.load(j)
    

    (it is easy to forget: the 's' is for 'string')

提交回复
热议问题