【发布时间】:2014-07-02 21:10:21
【问题描述】:
我有一个大型 excel 文档(2000 多行),它使用单元格来指定树结构,我想将其解析为 .json 文件。 excel 导出的 .csv 文档格式如下,其中 excel 文件中的逗号为空单元格:
Layer1category1,,,,,
,Layer2category,,,,
...
,,,,Layer5category1,
,,,,,item1
,,,,,item2
,,,,Layer5category2,
,,,,,item1
,,,Layer4category2,,
...
Layer1category2,,,,,
...
Layer1category8,,,,, // 这是最上层的最后一个类别
总之,Layer n 类别以 n-1 逗号开头,后跟 6-n 逗号,行以 5 开头逗号是最后一层,是字符串的格式,除了名字还有很多字段。
我希望将其转换为类似于以下内容的 .json 文件。我使用“名称”是因为除了名称之外,每个字段还与大量统计信息相关联,这些统计信息也需要进入 json 文件。
{"name" : "Layer1category1",
"children": [
{"name" : "Layer2category1",
"children" : [
{"name" : "Layer3category1"
"children" : [
...
{"name" : "Layer5category1",
"children" : [{"name" : "item1"}, {"name" : "item2"}],}
{"name" : "Layer5category2",
"children" : [{"name" : "item1"}],}
{"name" : "Layer4category2",
"children" : [
...
]}
"name" : "Layer1category2",
"children" : [ ... ]
}
有人对我如何解决这个问题有任何建议吗?我发现的 csv 到 json 转换器不支持多层结构。谢谢!
【问题讨论】: