【问题标题】:Node Js + JSON to Excel with inner json content带有内部 json 内容的节点 Js + JSON 到 Excel
【发布时间】:2015-12-28 22:26:46
【问题描述】:

我尝试使用节点模块(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.身份证, 2.标题, 3.关键词, 4.可见, 5.介绍, 6.目标

结果得到了,但问题在于介绍和目标列的值只得到 [object][object],[object][object]

预期输出:

所有 json 对象的内部都应该是带有值的标题。

【问题讨论】:

  • 鉴于您的示例 JSON,您希望 introduction 列中包含的值是多少?
  • @JackZelig - 我添加了我的示例 json 文件。请在此处查看。 jsfiddle.net/rajinikumarr/oyn5a397
  • 谢谢,但这仍然不能回答我的问题:)

标签: json node.js excel


【解决方案1】:

你可以添加这两行:

jsonObject[0].introduction = jsonObject[0].introduction.title;
jsonObject[0].objectives = jsonObject[0].objectives[0].title;

jsonObject 包含您的 json。

这当然只适用于数组中的第一个元素,并且只选择第一个目标的标题。如果您要导入不止一行和/或目标,则必须编写一些额外的逻辑。

【讨论】:

    猜你喜欢
    • 2016-08-11
    • 1970-01-01
    • 2017-10-07
    • 1970-01-01
    • 1970-01-01
    • 2018-09-01
    • 2018-07-03
    • 1970-01-01
    • 2021-11-28
    相关资源
    最近更新 更多