4

I'm having some trouble decoding this json in python.

From basehttpserver I'm getting back

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

which I'm putting into simplejsondecoder with

data = simplejson.loads(s)

but when I look at the length of data it's coming back with 1, not 5 for the json objects like I'm expecting.

Here's all of the code, incase 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

1 Answer 1

8

When you decode the JSON you get exactly what it looks like, a list containing a single item.

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

Sign up to request clarification or add additional context in comments.

1 Comment

Well, I feel dumb. Thanks Andrew!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.