Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.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
JSON_错误_状态_不匹配和JSON_错误_语法php常量之间的差异_Php_Json_Constraints_Json Deserialization - Fatal编程技术网

JSON_错误_状态_不匹配和JSON_错误_语法php常量之间的差异

JSON_错误_状态_不匹配和JSON_错误_语法php常量之间的差异,php,json,constraints,json-deserialization,Php,Json,Constraints,Json Deserialization,JSON错误状态不匹配和JSON错误语法常量之间有什么区别? 表示JSON_错误_状态_不匹配-无效或格式错误的JSON和JSON_错误_语法-语法错误。但是“语法错误”是“无效或格式错误的json”,不是吗 我们还发现了一个有趣的例子 如果我运行代码 $str = '{"j": 1 ] }'; $a = json_decode($str); var_dump($a); //NULL var_dump(json_last_error()); //2 var_dump(json_last_err

JSON错误状态不匹配和JSON错误语法常量之间有什么区别? 表示JSON_错误_状态_不匹配-无效或格式错误的JSON和JSON_错误_语法-语法错误。但是“语法错误”是“无效或格式错误的json”,不是吗

我们还发现了一个有趣的例子 如果我运行代码

$str = '{"j": 1 ] }';
$a = json_decode($str);

var_dump($a); //NULL
var_dump(json_last_error()); //2
var_dump(json_last_error_msg()); // State mismatch (invalid or malformed JSON)
在PHP7.0.6中,输出是

NULL
int(2)
string(42) "State mismatch (invalid or malformed JSON)"
NULL
int(2)
string(42) "State mismatch (invalid or malformed JSON)"
PHP 5.6.28

NULL
int(4)
string(35) "object value separator ',' expected"
PHP 5.6.18

NULL
int(4)
string(35) "object value separator ',' expected"
当我在这里运行代码时 在任何情况下,输出都是无效的

NULL
int(2)
string(42) "State mismatch (invalid or malformed JSON)"
NULL
int(2)
string(42) "State mismatch (invalid or malformed JSON)"

有人知道什么输出是正确的,为什么吗?

“PHP5中的解码是由Douglas Crockford基于JSON_检查器的解析器处理的。PHP7附带了一个全新的、经过改进的解析器,该解析器是专门为PHP编写的,并根据PHP许可证进行许可的。”这项服务,你为什么选择PHP5.6使用php版本5.6和第7版的解析器?