我想转换类似于此的对象:
{
"team1": {
"test123": [{
"players":"3",
"city":"blabla"
"date": null,
"country": "NZ",
}, {
"players":"7",
"city":"blabla2"
"date": null,
"country": "US",
}]
}
}
并接收一个包含 - >的数组对于一个对象,键和数组将连接数组的值。 例如:
["team1","test123",[{
"players":"3",
"city":"blabla"
"date": null,
"country": "NZ",
}, {
"players":"7",
"city":"blabla2"
"date": null,
"country": "US",
}]]
我试图在数组上运行递归,但它没有用。
*我的物体可能更大,铲斗+未知标签
尝试过这样的事情,但没有奏效:
function rec(obj) {
var res = [];
for(var key in obj) {
if (angular.isArray(obj[key])){
res.concat(obj[key]);
}
else {
rec(obj[key]);
res.push(key);
}
}
return res;
}