[英]I want to store the data of "KEY" & "textValue" as a json and send it as response in node.js for app.get("/api", (req, res)
我正在使用 node.js 和 react.js 处理 GCP Document AI,在给定的代码中,我创建了 json 结构( var jsonResult ),然后在 for 循环中,只有当我执行console.log(钥匙); 和console.log(textValue); 但我想将所有这些数据存储为json然后我想使用 node.js 片段res.json(JSON.stringify(jsonResult));发送json作为响应
请问有人可以帮我吗?
var jsonResult = [{
key:" ",
value:" "
}];
console.log('Document processing complete.');
const {document} = result;
for (let i=0;i<document.entities.length;i++)
{
var key = document.entities[i].type;
var textValue = document.entities[i].textAnchor !== null ? document.entities[i].textAnchor.content : '';
// console.log(key);
// console.log(textValue);
jsonResult[i].key = key;
jsonResult[i].textValue = textValue;
}
res.json(JSON.stringify(jsonResult));
const data = result.document.entities;
let jsonArray = [];
for (let i = 0; i < data.length; i++)
{
let key = data[i]?.type;
let value = !data[i]?.textAnchor ? data[i]?.textAnchor?.content : '';
if (key && value)
jsonArray.push({key: key, textValue: value });
}
res.json(JSON.stringify(jsonArray));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.