标签:
var str1 =‘[{"name":"kevin","age":18},{"name":"rose","age":16}]‘;
String.prototype.transArray=function(){
var str =this.replace(/\[/,‘‘);
var newstr = str.replace(/\]/,‘‘);
var arr1 = newstr.split(‘,‘);
var jsonstr,arr2=[];
for(var i=0;i<arr1.length;i++){
jsonstr = arr1[i]+‘,‘+arr1[i+1];
arr2.push(JSON.parse(jsonstr));
i++;
}
return arr2;
}
var k = str1.transArray();
console.log(k);
将json数组字符串转换为json数组对象(值是json对象的数组)
标签:
原文地址:http://www.cnblogs.com/toward-the-sun/p/4343444.html