{ "id": "some", "title": "some", "author": { "name": "\u95eb\u9759"
}, "link": [{ "@attributes": { "href": "http://localhost/", "rel": "some"
}
},
{ "@attributes": { "href": "http://localhost/", "rel": "some"
}
},
{ "@attributes": { "href": "http://localhost/", "rel": "some"
}
}]
}
2 回答
![?](http://img1.sycdn.imooc.com/54584ee0000179f302200220-100-100.jpg)
Smart猫小萌
TA贡献1911条经验 获得超7个赞
var req = { ...你的返回对象... };var first_href_val = req.link[0]['@attributes'];
![?](http://img1.sycdn.imooc.com/545869510001a20b02200220-100-100.jpg)
三国纷争
TA贡献1804条经验 获得超7个赞
function getJsonValue(obj,name){ var result = null; var value = null; for(var key in obj){ value = obj[key]; if(key == name){ return value; } else { if( typeof value == "object" ){ result = getJsonValue(value,name); } } } return result; }
采用递归方式来查找josn中的你需要的key.
但是还不支持 数组,你可以自己扩充,思路就是这样!
var taskId = getJsonValue(jsonobj,"history");console.log(taskId);var jsonobj = { "semantic":{"taskId":"8.4.3"},"history":"cn.xxxx.fund"};
添加回答
举报
0/150
提交
取消