我无法从下面的JSON输出中的“statisticsEvidence”中获取值作为“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;
}
});
请建议如何将statisticsEvidence中的值作为数组获取。
答案 0 :(得分: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
数据中的对象不是数组。