js怎样将数组转换为json

JavaScript023

js怎样将数组转换为json,第1张

//数组转json串var arr = [1,2,3, { a : 1 } ]

JSON.stringify( arr )

//json字符串转数组var jsonStr = '[1,2,3,{"a":1}]'

JSON.parse( jsonStr )

var arr = ['1600', '2000', '0', '-6000','-8000']

var obj = {data:arr}

console.log(obj)

或者:

var arr = ['1600', '2000', '0', '-6000','-8000']

var obj = {}

obj.data = arr

console.log(obj)