我在jquery中获取数据如下,我想转换为一维字符串数组
[
{"2065559857":"2065559482"},
{"2065559857":"2065553412"},
{"2065559857":"2065558122"},
{"2065559857":"7155354848"},
{"2065559857":"7155577723"},
{"2065559857":"7153555598"},
{"2065559857":"2065551189"},
{"2065559857":"7155544434"},
{"2065559857":"7296363080"},
{"2065559857":"7890128703"},
{"2065559857":"8483894326"},
{"2065559857":"9077659950"},
{"2065559857":"9671425573"}
]
转换为
["2065559482","2065559857","2065553412",.....]
答案 0 :(得分:1)
您可以使用map
方法将每个对象转换为包含键和值的数组,然后使用相同的方法连接所有数组:
a = $.map(a, function(o){ return $.map(o, function(x, i){ return [x, i]; }); });
答案 1 :(得分:0)
怎么样......
var jsonString = [{"2065559857":"2065559482"},{"2065559857":"2065553412"},{"2065559857":"2065558122"}];
var myArray = [];
for(var i in jsonString){
myArray.push([i,jsonString[i]]);
}
或jQuery:
var jsonString = [{"2065559857":"2065559482"},{"2065559857":"2065553412"},{"2065559857":"2065558122"}];
var myArray = [];
$.each(jsonString, function(key,value){
myArray.push(value);
});