0

我无法从以下 JSON 输出中的“statisticalEvidence”获取值作为“key”、“value”对。

JSON输出:

{
    "query": {
        "count": 1,
        "lang": "en-US",
        "results": {
            "entities": {
                "total": "10",
                "lang": "en-US",
                "entity": [
                    {
                    "id": "FZZNDK3XM3VIPLW76QHCAYF2D4",
                    "rank": "10",
                    "scores": {
                        "score": {
                            "attribute": "contentCreator",
                            "context": "yct:001000012",
                            "value": "1.0",
                            "statisticalEvidence": "\"{\"totalNoOfAbusiveComments\":0,\"totalNoOfThumbsDown\":22,\"totalNoOfPositiveRatedComments\":70,\"totalNoOfReplies\":8,\"totalNoOfLikedComments\":20,\"totalNoOfEngagingReplies\":13,\"totalNoOfThumbsUp\":35,\"totalNoOfComments\":79}\""
                        }
                    }}
                ]
            }
        }
    }
}

我能够如下获取“id”:

$.get(url,function(data) {
    var json = jQuery.parseJSON(data);
    for(var i in json.query.results.entities.entity){
    var id = json.query.results.entities.entity[i].id;
        }
});

请建议如何将statisticalEvidence中的值作为数组获取。

4

1 回答 1

0

试试下面,

//should return the string
var se = json.query.results.entities.entity[i].scores.score.statisticalEvidence 

然后使用$.parseJSON

se = $.parseJSON(se);

完整代码:

$.get(url,function(data) {
    var json = jQuery.parseJSON(data);
    for(var i in json.query.results.entities.entity){
       var id = json.query.results.entities.entity[i].id;
       var se = $.parseJSON(json.query.results.entities.entity[i].scores.score.statisticalEvidence);
    }
});

注意: statisticalEvidence在您的数据中是一个对象而不是一个数组。

于 2012-10-12T16:26:45.510 回答