我尝试使用 Node 模块(https://www.npmjs.com/package/json2xls)将json转换为excel转换
我附上了示例 json 文件:
[ { "id":11, "title":"The Brain ", "keyTerms":"You should a", "visible":true, "introduction":{ "id":5336, "title":"Introductory Materials", "resources":[ { "id":22, "title":"Vocabulary - Brain and Nervous System", "description":""} ] }, "objectives":[ { "id":33, "title":"1. Describe how the nervous system is organized", "caContribution":5, "position":1, "resources":[ { "id":23024, "title":"Reading - How the Nervous System Works"} ] } ] } ]
获取 Excel 输出:
标题: 1.id, 2.标题, 3.关键术语, 4.可见, 5.简介, 6.目标
结果得到了,但问题出在简介和目标列值中,仅得到[object][object],[object][object]
预期输出:
所有 json 对象内部应以带有值的标题形式出现。
最佳答案
您可以添加这两行:
jsonObject[0].introduction = jsonObject[0].introduction.title;
jsonObject[0].objectives = jsonObject[0].objectives[0].title;
其中 jsonObject
包含您的 json。
这当然仅适用于数组中的第一个元素,并且它仅选择第一个目标的标题。如果您要导入多于一行和/或目标,则必须编写一些额外的逻辑。
关于json - Node Js + JSON 到 Excel 并包含内部 json 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34494823/