Hi,
Sorry for late reply. I had to switch to another project so this work
got delayed.
Actually, what I am doing is that I am receiving json data over HTTP
via GET. After debugging much, I have realized that the data also has
HTTP headers and other information that serializer is not able to
serialize. How can I extract json data from the complete data
(including HTTP information)?
This is the data I receive, i.e. p, and I want to extract json from it
and deserialize it for parsing.
HTTP/1.0 200 OK Date: Thu, 02 Sep 2010 08:37:39 GMT Server: WSGIServer/
0.1 Python/2.6.4 Content-Type: application/json [{"pk": 33, "model":
"hbexample.payment", "fields": {"confirm": true, "pDate": "2010-08-31
10:42:19", "waiting": false, "amount": 33.0, "p_try": 0, "booking":
34}}]
I have tried json.loads and json.dumps on this data.
With json.loads(p), I get the following error: expected string or
buffer
With json.dumps(p), I get the following error:
<django.http.HttpResponse object at 0x150da50> is not JSON
serializable
How do I address this problem? Any help regarding this would be
helpful.
Thanks and Looking forward,
Irum
On Aug 20, 9:33 pm, Reinout van Rees <
rein...@vanrees.org> wrote:
> On 08/20/2010 02:16 PM,irumwrote:
>
> > 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
>
> One small thing to try:
> response = HttpResponse('')
> instead of:
> response = HttpResponse()
>
> So: feed it an empty string.
>
> As it complains about being unreadable, perhaps you should stuff
> something into it. Just a pretty wild guess...
>
> Reinout
>
> --
> Reinout van Rees -
rein...@vanrees.org -
http://reinout.vanrees.org
> Programmer athttp://
www.nelen-schuurmans.nl