0

如果我有一个包含多个 JSON 的网站,"usrId":我如何计算它存在多少次?我不知道是计算 JSON 对象更好,还是只计算网页上该词存在多少次,我也不知道如何开始,我该怎么做?

request(getusr, function(err, res, body) {
  let json = JSON.parse(body);
  let usramount = // count how many times usrId appears
})

示例 json:

  {  
     "id":"example",
     "usrId":"example"
  },
  {  
     "id":"example"
     "usrId":"example",
  },
4

1 回答 1

2
(body.match(/"usrId":/g) || []).length;

应该做的伎俩。

于 2018-07-06T15:12:38.590 回答