不知道为什么这不会转换,我会假设它可能与字符串有关,但我得到np输出.
$string = '[{title : "Comp 1 Product",columns : ["Our Vehicle","Features","Their Vehicle"], items : [["dcq","adv","asdvasdv"],["sdv","sdv","sdv"]]},{title : "qwefqw",columns : ["Section 1","Features","Section 2"],items : [["qqwec","qwe","qwegqwev"]]}]';
print_r(json_decode($string), true);
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激!
如果你看到:
<?php
header("Content-type: text/plain");
$string = '[{title : "Comp 1 Product",columns : ["Our Vehicle","Features","Their Vehicle"], items : [["dcq","adv","asdvasdv"],["sdv","sdv","sdv"]]},{title : "qwefqw",columns : ["Section 1","Features","Section 2"],items : [["qqwec","qwe","qwegqwev"]]}]';
print_r(json_decode($string), true);
print_r(json_last_error());
?>
Run Code Online (Sandbox Code Playgroud)
上面的代码返回a 4,这意味着JSON_ERROR_SYNTAX,这是JSON的语法错误.使用JSON Lint检查时,您的JSON将抛出:
你需要纠正它看起来像:
[{
"title": "Comp 1 Product",
"columns": ["Our Vehicle", "Features", "Their Vehicle"],
"items": [
["dcq", "adv", "asdvasdv"],
["sdv", "sdv", "sdv"]
]
}, {
"title": "qwefqw",
"columns": ["Section 1", "Features", "Section 2"],
"items": [
["qqwec", "qwe", "qwegqwev"]
]
}]
Run Code Online (Sandbox Code Playgroud)
你现在拥有的是一个JavaScript对象,而不是一个有效的JSON!