json - 计算一个特定的 json/word 出现了多少次
问题描述
如果我有一个包含多个 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",
},
解决方案
(body.match(/"usrId":/g) || []).length;
应该做的伎俩。
推荐阅读
- javascript - Sequelize 数据库错误列名不存在
- r - 如何返回分组数据中每组的异常值列表
- swift - 在 Disclosure 指示器后面的 TableViewCell 中将 ImageView 设置为全宽
- android - MotionLayout roundPercent 只工作一次
- python - 从进程输出读取时代码卡在循环中
- iis - 在哪里检查 IIS Express 中的默认模拟设置?
- c - 我遇到了字符串连接的问题
- mysql - 刚刚学习了一段 MySQL 语法的艰难方法 - 为什么它有效,它意味着什么?
- email - 尝试获取 Gmail SMTP 访问的授权令牌的范围无效
- java - 在二维排序数组中搜索元素