我如何使用simplejson在python中编写代码

时间:2010-03-31 14:53:39

标签: python json

我如何编写一个返回一个看起来像这个

的json元素的python程序
{1:{'name':foo,'age':xl}
  2:{'name':vee,'age':xx}
  ....
}

我的意思是我想要返回嵌套字典

我希望完成的是这样的事情

var foo = 1.name  # to the the value of name in the clientside

我希望这一切都有道理。英语是我的第二语言

提前致谢

1 个答案:

答案 0 :(得分:3)

>>> import simplejson as json 
    # "simplejson" works exactly the same as with "json"
>>> json.dumps({})
'{}'
>>> json.dumps({'asdf':1,'poi':[2,3,4,{'qwer':5}]})
'{"asdf": 1, "poi": [2, 3, 4, {"qwer": 5}]}'
>>>