如下所示:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9162.html
string =" { "status": "error", "messages": ["Could not find resource or operation 'BZK1.MapServer' on the system."], "code": 404 }"
print '对象:' string文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9162.html
print '取值:' json.loads(string)['code']文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9162.html
输出结果为:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9162.html
对象:{u'status': u'error', u'code': 404, u'messages': [u"Could not find resource or operation 'BZK1.MapServer' on the system."]}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9162.html
取值:404文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9162.html
将对象转成字符串:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9162.html
resultJson = {"state": 1} print json.dumps(resultJson)
分别使用了Json包中的loads()方法和dumps()方法文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9162.html