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

Posted tibetanmastiff

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Python]json对象转换出错expected string or buffer python相关的知识,希望对你有一定的参考价值。

【问题】

今天在使用python中的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‘}

 

【分析解决】

经过调试,最终发现,python中默认使用单引号表示字符串"‘" 所以当,使用字符串符值以后,python会把双引号转换为单引号。

而json是不支持单引号的。可以用下面的方法转换

json_string=json.dumps(s)

str=json.loads(json_string)

以上是关于[Python]json对象转换出错expected string or buffer python的主要内容,如果未能解决你的问题,请参考以下文章