一个用于修复JSON的工具库,受 JsonRepair 启发的C#重写版(所以投了原创)
关于为什么有这种工具,参考:"How to fix JSON and validate it with ease"
关于为什么有这种工具,参考:"How to fix JSON and validate it with ease"
如何使用
C#:
using JsonRepairSharp.Class;
// ...
var fixedJson = JsonRepairCore.JsonRepair(rawJson);
// ...
// You can also catch the JsonRepairError exception to handle the case where the library failed to fix the JSON.
支持修复的列表
- 在键周围添加缺失的引号
- 添加缺失的escape characters
- 添加缺失的逗号
- 添加缺失的括号
- 被截断的JSON*
- 用双引号替换单引号
- 将特殊引号替换为可接受的双引号
- 转换不被接受的空格为普通空格
- 将Python大写开头的一些值改为小写开头和可接受的形式(比如True、False、None...)
- 删除尾随逗号
- 删除注释,如 /* ... */ 和 // ...
- 删除数组和对象中的省略号,如 [1, 2, 3, ...]
- 删除 JSONP 符号,如回调 ({ ... })
- 删除转义字符串中的转义字符,如 {\"stringified\": \"content\"}
- 删除 MongoDB 数据类型,如 NumberLong(2) 和 ISODate("2012-12-19T06:01:17.171Z")
- 将 "使用加号" + "进行拼接的这种字符串" 重新组合
- 将类似如下的直接拼接的两个未分开的json对象组合进数组:
JSON:{ "id": 1, "name": "John" } { "id": 2, "name": "Sarah" }
- JRS支持流处理,所以具备很强大的大文件处理能力.