我似乎在将数组在PHP/JS之间进行转换时遇到了问题。我使用JavaScript中的XmlHttpRequest向一个PHP页面发送请求,该页面使用json_encode对多维(2D)数组进行编码。
当接收到字符串时,我使用JSON.parse()解码字符串,但它返回的是一个一维数组。有没有办法将JSON字符串解析成多维数组而不是单个维度?
以下是从CSV文件接收到的JSON示例:
当接收到字符串时,我使用JSON.parse()解码字符串,但它返回的是一个一维数组。有没有办法将JSON字符串解析成多维数组而不是单个维度?
以下是从CSV文件接收到的JSON示例:
[
{
"rating": "0",
"title": "The Killing Kind",
"author": "John Connolly",
"type": "Book",
"asin": "0340771224",
"tags": "",
"review": "i still haven't had time to read this one..."
},
{
"rating": "0",
"title": "The Third Secret",
"author": "Steve Berry",
"type": "Book",
"asin": "0340899263",
"tags": "",
"review": "need to find time to read this book"
},
{
"rating": "3",
"title": "The Last Templar",
"author": "Raymond Khoury",
"type": "Book",
"asin": "0752880705",
"tags": "",
"review": ""
},
{
"rating": "5",
"title": "The Traveller",
"author": "John Twelve Hawks",
"type": "Book",
"asin": "059305430X",
"tags": "",
"review": ""
},
{
"rating": "4",
"title": "Crisis Four",
"author": "Andy Mcnab",
"type": "Book",
"asin": "0345428080",
"tags": "",
"review": ""
},
{
"rating": "5",
"title": "Prey",
"author": "Michael Crichton",
"type": "Book",
"asin": "0007154534",
"tags": "",
"review": ""
},
{
"rating": "3",
"title": "The Broker (Paperback)",
"author": "John Grisham",
"type": "Book",
"asin": "0440241588",
"tags": "book johngrisham",
"review": "good book, but is slow in the middle"
},
{
"rating": "3",
"title": "Without Blood (Paperback)",
"author": "Alessandro Baricco",
"type": "Book",
"asin": "1841955744",
"tags": "",
"review": ""
},
{
"rating": "5",
"title": "State of Fear (Paperback)",
"author": "Michael Crichton",
"type": "Book",
"asin": "0061015733",
"tags": "",
"review": ""
},
{
"rating": "4",
"title": "The Rule of Four (Paperback)",
"author": "Ian Caldwell",
"type": "Book",
"asin": "0099451956",
"tags": "book bestseller",
"review": ""
},
{
"rating": "4",
"title": "Deception Point (Paperback)",
"author": "Dan Brown",
"type": "Book",
"asin": "0671027387",
"tags": "book danbrown bestseller",
"review": ""
},
{
"rating": "5",
"title": "Digital Fortress : A Thriller (Mass Market Paperback)",
"author": "Dan Brown",
"type": "Book",
"asin": "0312995423",
"tags": "book danbrown bestseller",
"review": ""
},
{
"rating": "5",
"title": "Angels & Demons (Mass Market Paperback)",
"author": "Dan Brown",
"type": "Book",
"asin": "0671027360",
"tags": "book danbrown bestseller",
"review": ""
},
{
"rating": "4",
"title": "The Da Vinci Code (Hardcover)",
"author": "Dan Brown",
"type": " Book ",
"asin": "0385504209",
"tags": "book movie danbrown bestseller davinci",
"review": ""
}
]
在解析后,如果我尝试使用myArr [0] [1]访问它,它会显示为未定义。
如果这很明显,请原谅我,我是JS和JSON的新手。