[英]JSON valid format in php
I'm processing a lot of json files but some of them have invalid format. 我正在处理很多json文件,但其中一些格式无效。
Is there a library to find a JSON format error? 是否有找到JSON格式错误的库?
I want error messages like: "Found error line 100 after {"property":val{" to easily find the line and fix it manually. 我希望这样的错误消息:“在{“ property”:val {“之后找到错误行100,以便轻松找到该行并手动进行修复。
Each json file has 500+ lines. 每个json文件有500多行。
Is there a library to find a JSON format error?
是否有找到JSON格式错误的库?
You can try to use a PHP tool like JSON Lint . 您可以尝试使用像JSON Lint这样的PHP工具。 Here is example usage in PHP:
这是PHP中的示例用法:
use Seld\JsonLint\JsonParser;
$parser = new JsonParser();
// returns null if it's valid json, or a ParsingException object.
$parser->lint($json);
// Call getMessage() on the exception object to get
// a well formatted error message error like this
// Parse error on line 2:
// ... "key": "value" "numbers": [1, 2, 3]
// ----------------------^
// Expected one of: 'EOF', '}', ':', ',', ']'
// Call getDetails() on the exception to get more info.
// returns parsed json, like json_decode() does, but slower, throws
// exceptions on failure.
$parser->parse($json);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.