[Python]json对象转换出错expected string or buffer python

【问题】python

今天在使用python中的json转换碰到一个问题:json

    错误显示: expected string or buffer调试

    json内容以下:字符串

{u'err_no': 0, u'corpus_no': u'6594675362334657196', u'err_msg': u'success.', u'result': [u'\uff0c'], u'sn': u'829195370711535442509'}string

 

【分析解决】

通过调试,最终发现,python中默认使用单引号表示字符串"'" 因此当,使用字符串符值之后,python会把双引号转换为单引号。方法

而json是不支持单引号的。能够用下面的方法转换co

json_string=json.dumps(s)字符

str=json.loads(json_string)错误

相关文章
相关标签/搜索