如果你看到:
<?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());
?>
上面的代碼返回一個4
,這意味着JSON_ERROR_SYNTAX
,這是使用JSON語法錯誤。當使用JSON林特選中,您的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"]
]
}]
你現在有什麼是JavaScript對象,而不是一個有效JSON!
這不是有效的JSON。在JSON中,屬性名稱需要用雙引號。 – Barmar
那個字符串從哪裏來的?您需要修復源代碼,以便它能夠正確創建JSON。它應該使用JSON庫,而不是手動構建它。 – Barmar
我已經發布了調試這些問題的方法,並找出問題所在。請在源頭修改。 –