[英]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.