我有相同的数据,但它有很多。我必须在列表中计算ID'v1'的总数。我需要做什么。
{
"_id": "5416cb72603b9c3c7b630d76",
"V1": "34c2cc7b-a650-6d53-9fd2-eb0dd77c4b85",
"V2": "122.170.60.1741410780012332",
"V3": 1234,
"V4": "122.170.60.174",
"V5": "1280*899",
"V6": "Window",
"V7": "",
"V9": 23.039568000000003,
"V10": 72.56600399999999,
"V11": "Chrome:37.0.2062.120",
"PubisherId": "53d919366ee580a63185572f",
"PublicationID": "53ce129671b91d9e2c5907e7",
"IssueID": "1408703918",
"timestamp": 1410780018
},
答案 0 :(得分:0)
var idCount = 0;
arr = JSON.parse('[{...},{...},{...}]');//json
arr.map(function(val){
if(val.v1) {
idCount++
}
});
console.log(idCount);
答案 1 :(得分:0)
也许是这样的?我计算DISTINCT V1值。
function count_v1(in_obj){
var obj = JSON.parse(in_obj);
var found_id = {};
var cnt = 0;
for (var i = 0; i < obj.length; i++){
if (obj[i]['V1'] != undefined)
if (found_id[obj[i]['V1']] == undefined){
found_id[obj[i]['V1']] = 1;
cnt++
}
}
return cnt;
}