Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php中的JSON有效格式_Php_Json - Fatal编程技术网

php中的JSON有效格式

php中的JSON有效格式,php,json,Php,Json,我正在处理很多json文件,但其中一些文件的格式无效 是否有用于查找JSON格式错误的库 我想要错误消息,比如:“在{”属性“:val{”之后找到错误行100,以便轻松找到该行并手动修复它 每个json文件有500多行 是否有用于查找JSON格式错误的库 您可以尝试使用PHP工具,如。以下是PHP中的示例用法: use Seld\JsonLint\JsonParser; $parser = new JsonParser(); // returns null if it's valid jso

我正在处理很多json文件,但其中一些文件的格式无效

是否有用于查找JSON格式错误的库

我想要错误消息,比如:“在{”属性“:val{”之后找到错误行100,以便轻松找到该行并手动修复它

每个json文件有500多行

是否有用于查找JSON格式错误的库

您可以尝试使用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);

似乎您看到的错误正告诉您错误的确切位置。@MartinKonecny我有很多类型的格式错误,如带回车符的值或无效的带引号的字符串等。您可能需要手动修复这些错误:(没错!但我需要知道行号才能快速修复,json文件有500多行。您使用什么处理这些文件?哪种语言?