2016-06-13 101 views
-3
[["January 2016", "February 2016", "March 2016", "April 2016", "May 2016", "June 2016"], ["person1", 23274, 24470, 44140, 74651, 42538, 23076], ["person2", 2390, 14333, 9480, 15387, 15006, 4941], .. 

嗨,如何將存儲此Json到數組中,如果在Javascript中的數組?不知道如何做到這一點。將json存儲到數組中

謝謝!

+1

'JSON.parse()來'? –

+0

這不是有效的JSON。實際上,它是幾個數組。你想把這些數組並將它們變成JSON或什麼? – sbeliv01

+0

可能重複的http://stackoverflow.com/questions/20881213/converting-json-object-into-javascript-array –

回答

1

假設你正在接收數據作爲一個字符串,你可以使用JSON.parse()

var str = '[["January 2016", "February 2016", "March 2016", "April 2016", "May 2016", "June 2016"], ["person1", 23274, 24470, 44140, 74651, 42538, 23076], ["person2", 2390, 14333, 9480, 15387, 15006, 4941]...'; 

var myArr = JSON.parse(str); 
0

這已經是一個JSON。實施例在Javascript:

var arrayOfArrays = [["elem1","elem2"], ["elem3","elem4"]] 

JSON.stringify(arrayOfArrays) 

response: "[["elem1","elem2"],["elem3","elem4"]]" 

JSON.parse('[["elem1","elem2"],["elem3","elem4"]]') 
response: [Array[2], Array[2]] 
0
JSON.parse('[["January 2016", "February 2016", "March 2016", "April 2016", "May 2016", "June 2016"], ["person1", 23274, 24470, 44140, 74651, 42538, 23076], ["person2", 2390, 14333, 9480, 15387, 15006, 4941]]')