需要帮助使用Node.js将嵌套数组解析为单独的对象。非常感谢您的帮助。
我需要在最终输出中没有这些 -
"Status": "0",
"Message": "OK",
"Count": "3724",
和
我需要将以下内容作为单独的json对象 -
拥有以下json数据样本(截断):
{
"Status": "0",
"Message": "OK",
"Count": "3724",
"InvoiceRecords": [
{
"InvoiceDate": "8/9/2017 12:00:00 AM",
"InvoiceLocation": "002",
"InvoiceNumber": "2004085",
"InvoiceRecordHeaderDetails": [
{
"InvNum": "2004085",
"Location": "002",
"InvDate": "8/9/2017 12:00:00 AM"
}
],
"InvoiceRecordSplitDetails": [
{
"UniqueID": "1757391",
"InvNum": "2004085",
"Location": "002",
"InvoiceDate": "8/9/2017 12:00:00 AM"
}
],
"InvoiceRecordLineItemDetails": [
{
"UniqueID": "3939934",
"InvNum": "2004085",
"Location": "002",
"InvoiceDate": "8/9/2017 12:00:00 AM"
}
],
"InvoiceTaxCodeDetails": [
{
"InvoiceDate": "8/9/2017 12:00:00 AM",
"Location": "002",
"InvNum": "2004085",
}
]
}
]
}
更新2
@克里斯-adorna
按照你的指示(我认为),但遇到了障碍(帮助?)
// Parse input file data as json
var jsonContent = JSON.parse(fs.readFileSync(inputFile, 'utf8'));
//1. Create 4 empty arrays, one each for record header, splits, line items and tax code details
var recordHeader;
var splits;
var lineItems;
var taxCodes;
//2. Use a forEach function to iterate through InvoiceRecords
var i;
for (i = 0; i < jsonContent.length; i++) {
var record = jsonContent[i].InvoiceRecords;
};
console.log(record);
第2步没有得到任何东西,但未定义&#39;在控制台中。
答案 0 :(得分:0)