Have you tried looking at the raw data to see if it is what you expect (capture to a file or pdb.set_trace() is your friend)?
Have you tried (assuming relatively recent python, >= 2.6 I think) loads from the json module? Bill On Fri, Aug 20, 2010 at 8:16 AM, irum <[email protected]> wrote: > Hi, > I am trying to parse json, loop through it and access its data. > At first I tried this: > > for obj in serializers.deserialize("json", p): > a=2 > response = HttpResponse() > response.status_code = 200 > return response > > Here 'p' has the json data returned to me by another view. I have > validated it in http://www.jsonlint.com/ and it does not have any > error. > > This gave attribute error. > AttributeError at /bookings/52/cancel/ > 'HttpResponse' object has no attribute 'read' > > The problem I am sure is not in HttpResponse object as it works fine > when I comment out the line accessing object of deserialized data i.e > for obj in serializers.deserialize("json", p) > > I then tried writing this: > > deserialized = serializers.deserialize("json", > self.request.raw_post_data) > d = list(deserialized)[0].object > > and also this: > > deserialized = serializers.deserialize("json", > self.request.raw_post_data) > d = list(deserialized).object > > I again get same error. It works fine if the second line: put_bookmark > = list(deserialized)[0].object , is commented out. But, when I > uncomment it to access object of deserialized data I get the same > error. > > After many trial and errors, I am convinced the problem is when I try > to access object of deserialized data. I also referred to this thread: > http://groups.google.com/group/django-users/browse_thread/thread/87bd6951b4aebd00/d8e0a547be1583a8?lnk=gst&q=deserialize#d8e0a547be1583a8 > in the discussion group. In this thread also the problem trickles down > to access object of deserialzed data but no further solution is > available. > > I don want to use simplejson. Can someone give me a solution to this > problem and help me fix this. > > Thanks, > Irum > > > I get the attribute error: > 'HttpResponse' object has no attribute 'read' > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

