Re: Serializing non-queryset data

2010-07-07 Thread Jonathan Hayward
Never mind; I found:

import json

def view(request):
...
my_result = ...
return HttpResponse(json.dumps(my_result), mimetype="application/json")

On Wed, Jul 7, 2010 at 6:05 PM, Jonathan Hayward <
christos.jonathan.hayw...@gmail.com> wrote:

> I just tried:
>
> json_serializer.serialize(result, ensure_ascii = False, stream = response)
>
> where result was boolean. I got an error complaining that it was not
> iterable, and http://docs.djangoproject.com/en/dev/topics/serialization/seems 
> to discuss serialization of querysets.
>
> In this case I can easily enough create JSON manually, but is there a
> preferred way to take dicts, lists, strings, numbers, etc. and render a
> structure as JSON?
>
> --
> → Jonathan Hayward, christos.jonathan.hayw...@gmail.com
> → An Orthodox Christian author: theology, literature, et cetera.
> → My award-winning collection is available for free reading online:
> ☩ I invite you to visit my main site at http://JonathansCorner.com/
>



-- 
→ Jonathan Hayward, christos.jonathan.hayw...@gmail.com
→ An Orthodox Christian author: theology, literature, et cetera.
→ My award-winning collection is available for free reading online:
☩ I invite you to visit my main site at http://JonathansCorner.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Serializing non-queryset data

2010-07-07 Thread Jonathan Hayward
I just tried:

json_serializer.serialize(result, ensure_ascii = False, stream = response)

where result was boolean. I got an error complaining that it was not
iterable, and http://docs.djangoproject.com/en/dev/topics/serialization/seems
to discuss serialization of querysets.

In this case I can easily enough create JSON manually, but is there a
preferred way to take dicts, lists, strings, numbers, etc. and render a
structure as JSON?

-- 
→ Jonathan Hayward, christos.jonathan.hayw...@gmail.com
→ An Orthodox Christian author: theology, literature, et cetera.
→ My award-winning collection is available for free reading online:
☩ I invite you to visit my main site at http://JonathansCorner.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.