How do I turn a dictionary into a JSON object using simplejson, in Python? [closed]
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this questionIt's something like this, but this example seems a little complicated.
import simplejson as json json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
My dictionary is:
myfruits = {'fruit':4, 'color':11}
How can I turn this into a JSON, and then use render_to_response to shoot it to a template? I'm usi开发者_开发知识库ng Django.
I think this is the easiest way to do it
import simplejson as json
myfruits = {'fruit':4, 'color':11}
json.dumps(myfruits)
use json.dumps()
(see doc here).
import simplejson
simplejson.dumps({'fruit':4, 'color':11})
精彩评论