开发者

How do I turn a dictionary into a JSON object using simplejson, in Python? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

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 question

It'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})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜