Python JSON Decoding

I am having trouble decrypting this json in python.

From basehttpserver i'm coming back

[ { "changed_aspect": "media", "object": "geography", "object_id": "1306", "subscription_id": 1326, "time": 1300570688 } ] 

which I put in simplejsondecoder with

 data = simplejson.loads(s) 

but when I look at the length of the data returned from 1, not 5 for json objects, as I expect.

Here is all the code if the problem lies elsewhere.

 class httpserver(BaseHTTPServer.BaseHTTPRequestHandler): def do_POST(self): self.data_string = self.rfile.read(int(self.headers['Content-Length'])) self.send_response(200) self.end_headers() data = simplejson.loads(self.data_string) print len(data) return 
+4
source share
1 answer

When you decode JSON, you get exactly what it looks like, a list containing one element.

data[0] should be the dictionary you expected to see.

+8
source

Source: https://habr.com/ru/post/1344407/


All Articles