JSON.parse UTF-8字符串 [英] JSON.parse UTF-8 string

查看:1022
本文介绍了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:


undefined: 306
,o:{type:uri,value: http ://got.dbpedia.org/resource/ \U00010331 \
^
语法错误:意外的标记U

undefined:306 , "o": { "type": "uri", "value": "http://got.dbpedia.org/resource/\U00010331\ ^ SyntaxError: Unexpected token U

这是我使用的行:

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字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆