[英]Parse unicode JSON string
I've some difficulties to parse a unicode JSON string. 我在解析Unicode JSON字符串时遇到一些困难。
sample: 样品:
js = "{'to': 1234, 'message': u'sample message', 'user': 65773722, 'msgId': 28198}"
I want to iterate the JSON object to retrieve the values. 我想迭代JSON对象以检索值。
I've already tried, json.dumps, json.loads and js.decode('unicode-escape'), but I keep getting error messages. 我已经尝试过json.dumps,json.loads和js.decode('unicode-escape'),但是我一直收到错误消息。
Please help..I'm stuck ! 请帮助..我被卡住了!
Many thanks ! 非常感谢 !
Unfortunately someone goofed, and that's not JSON. 不幸的是有人搞砸了,那不是JSON。
>>> ast.literal_eval(js)
{'to': 1234, 'message': u'sample message', 'user': 65773722, 'msgId': 28198}
it is not valid json 无效的json
s = "{'to': 1234, 'message': u'sample message', 'user': 65773722, 'msgId': 28198}"
valid = s.replace("u'", "'")
supervalid = v.replace("'", '"')
json.loads(super_valid)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.