Python中相当于PHP的json_encode是什么
可能重复的问题:
用Python轻松进行JSON编码
我想从数据库中获取一条记录,然后把它转换成JSON格式。我知道在使用PHP时可以用json_encode来做到这一点。但是在Python中我们该怎么做呢?
2 个回答
2
Python有好几种处理json的工具。我个人喜欢simplejson,因为它简单易用。
9
# Python 2.6+
import json
result = json.dumps(value)
or
# Python 2.6+
import json
json.dump(value, out_file)
我从谷歌的第一个搜索结果找到了这个。http://www.php2python.com/wiki/function.json-encode/
在问一些简单且可以搜索到的问题之前,请先自己查查资料!