开发者

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

开发者 https://www.devze.com 2022-12-15 15:19 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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

精彩评论

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