python json.loads u_解决Python 2下的json.loads()导致的unicode编码问题,json数据转换前面带u,去掉字典类型前面的u...
https://blog.csdn.net/qq_24342335/article/details/84561341def unicode_convert(input):if isinstance(input, dict):return {unicode_convert(key): unicode_convert(value) for key, value in input.iteritems()
https://blog.csdn.net/qq_24342335/article/details/84561341
def unicode_convert(input):
if isinstance(input, dict):
return {unicode_convert(key): unicode_convert(value) for key, value in input.iteritems()}
elif isinstance(input, list):
return [unicode_convert(element) for element in input]
elif isinstance(input, unicode):
return input.encode(‘utf-8‘)
else:
return input
————————————————
test = {"name": "扎克伯格", "age":18}
print test
test_json = json.dumps(test, ensure_ascii=False)
print test_json
test1 = json.loads(test_json)
print test1
test2 = unicode_convert(json.loads(test_json))
print test2
————————————————
{‘age‘: 18, ‘name‘: ‘\xe6\x89\x8e\xe5\x85\x8b\xe4\xbc\xaf\xe6\xa0\xbc‘}
{"age": 18, "name": "扎克伯格"}
{u‘age‘: 18, u‘name‘: u‘\u624e\u514b\u4f2f\u683c‘}
{‘age‘: 18, ‘name‘: ‘\xe6\x89\x8e\xe5\x85\x8b\xe4\xbc\xaf\xe6\xa0\xbc‘}
————————————————
版权声明:本文为CSDN博主「Wally~」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_24342335/java/article/details/84561341
原文:https://www.cnblogs.com/angdh/p/12673009.html
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)