本文介绍了JSON.parse UTF-8字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试解析UTF-8编码的字符串,但JSON.parse在这一行上窒息:
I'm trying to parse a UTF-8 encoded string, but JSON.parse is choking on this line:
这是我使用的行:
var object = JSON.parse(data);
我也试过这条线,但没有成功:
I've also tried with this line, but no success:
var object = JSON.parse(data.toString('utf8'));
任何想法?
推荐答案
在JSON字符串中 \\ \\
字符后面可能没有大写的 U
字符。你的JSON无效。你需要一个小写 u
而不是应该x输出无效JSON的任何内容。
In a JSON string a \
character may not be followed by an uppercase U
character. Your JSON is invalid. You need a lowercase u
instead and should fix whatever is outputting the invalid JSON.
这篇关于JSON.parse UTF-8字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!