首页 > 开发 > JS > 正文

如何获取json对象中的特定值?

2017-09-05 13:02:52  来源:网友分享
{    "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"        }    }]}

如上,对于服务器返回的json数据,如何获取Link中第一个@attributes的href值?

解决方案

var req = { ...你的返回对象... };var first_href_val = req.link[0]['@attributes'];