首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Json不使用文件内容进行验证吗?

问Json不使用文件内容进行验证吗?
EN

Stack Overflow用户
提问于 2017-03-28 12:12:16
回答 2查看 53关注 0票数 0

我已经用正常的内容测试了我的json数据,这些数据运行良好。

S示例数据如下:

工作Json

代码语言:javascript
复制
 {
  "language": "XYZ",
  "content": {
    "GEN": "this is test",
    "EXO": "this is test"
   }
 }

不工作的json

代码语言:javascript
复制
 {
  "language": "XYZ",
  "content": {
    "GEN": "\id GEN\n\c 1\n\p\n\v 1 In the beginning God created the heavens and the earth.\n\v 2 And the earth was without form and was void form.",
    "EXO": "\id EXO\n\c 1\n\p\n\v 1 Now these are the names of the children of Israel, which came to Egypt; every man and his household came with Jacob\n\v 2 Reuben, Simeon, Levi, and Judah"
   }
}

检查屏幕截图中的工作和不工作json

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-03-28 12:41:52

对于转义序列,可以将对象转换为JSON字符串,然后进行如下解析

代码语言:javascript
复制
 var obj= {
            "language": "XYZ",
            "content": {
                "GEN": "\id GEN\n\c 1\n\p\n\v 1 In the beginning God created the heavens and the earth.\n\v 2 And the earth was without form and was void form.",
                "EXO": "\id EXO\n\c 1\n\p\n\v 1 Now these are the names of the children of Israel, which came to Egypt; every man and his household came with Jacob\n\v 2 Reuben, Simeon, Levi, and Judah"
            }
        };
        var json= JSON.stringify(obj);

这对你来说会更简单。

票数 0
EN

Stack Overflow用户

发布于 2017-03-28 12:30:59

JSON允许的唯一反斜杠转义序列是\b、\f、\n、\r、\t和\"。反斜杠的所有其他用途都必须转义为\\。问题是,\i (以及其他一些转义序列)对JSON没有任何意义,因此是语法错误。把它写成\\i。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43069242

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档