Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从json响应创建文本_Json_Node.js - Fatal编程技术网

从json响应创建文本

从json响应创建文本,json,node.js,Json,Node.js,我正在从我的节点js发出一个api调用,并得到一个json响应。下面是我的代码 apiServices.getCaseStatus("status", function(data) { console.log(JSON.stringify(data)); if (data) { console.log(`${data.length} is the length of t

我正在从我的节点js发出一个api调用,并得到一个json响应。下面是我的代码

apiServices.getCaseStatus("status", function(data) {
                    console.log(JSON.stringify(data));
                    if (data) {
                        console.log(`${data.length} is the length of the data returned`);
                    }
我在调用API时得到的JSON如下所示

[
  {
    "status_details": "requirements",
    "status": "pending"
  },
  {
    "status_details": "requirements",
    "status": "pending"
  },
  {
   "status_details": "forms",
    "status": "pending"
   },
  {
    "status_details": "decision",
    "status": "pending"
   }
]
这里我想要一个如下的声明

console.log(`${data.length} is the length of the data returned, 2 are pending requirements, 1 is pending decision, and 1 is pending forms`);
我不知道怎样才能得到这样的结果。请帮我做这件事


谢谢

我会对它们进行分组并按
状态\u详细信息进行计数
,然后从对象创建字符串
reduce
将通过映射其对象键返回

设d=[{
“状态详情”:“要求”,
“状态”:“待定”
},
{
“状态详情”:“要求”,
“状态”:“待定”
},
{
“状态详情”:“表格”,
“状态”:“待定”
},
{
“状态详情”:“决定”,
“状态”:“待定”
}
];
让r=d.减少((a,b)=>{
a[b.状态详情]=a[b.状态详情]|{
计数:0
};
a[b.状态\详细信息].计数+=1;
a[b.status\u details]。status=b.status;
返回a;
}, {});
让txt=[d.length+“是返回的数据的长度”,Object.keys(r).map(e=>'+r[e].count+(r[e].count>1?'are':'is')+r[e].join(',');

console.log(txt)我会将它们分组并按
状态详细信息进行计数,然后从对象创建字符串
reduce
将通过映射其对象键返回

设d=[{
“状态详情”:“要求”,
“状态”:“待定”
},
{
“状态详情”:“要求”,
“状态”:“待定”
},
{
“状态详情”:“表格”,
“状态”:“待定”
},
{
“状态详情”:“决定”,
“状态”:“待定”
}
];
让r=d.减少((a,b)=>{
a[b.状态详情]=a[b.状态详情]|{
计数:0
};
a[b.状态\详细信息].计数+=1;
a[b.status\u details]。status=b.status;
返回a;
}, {});
让txt=[d.length+“是返回的数据的长度”,Object.keys(r).map(e=>'+r[e].count+(r[e].count>1?'are':'is')+r[e].join(',');
console.log(txt)