gpt4 book ai didi

java - 如何使用 Java 将 json 数组转换为 CSV 文件

转载 作者:行者123 更新时间:2023-12-01 18:15:01 26 4
gpt4 key购买 nike

我一直在搜索如何将 json 数组转换为 CSV 文件,但无法得到明确的答案。如果有人已经做到了,请帮助我如何转换它或只是分享任何有用的文档之类的,谢谢。

最佳答案

图书馆链接:https://github.com/opendevl/Json2Flat

示例输出如下:https://j2flateval.herokuapp.com

 // There are some typos in the data.

// You can try json2flat for converting JSON docs to get an equivalent CSV representation.
// If you want to try for more JSON doc click here.

// For the JSON data :

{
"results": [{

"geo_position": {
"Field1": 11,
"Field2": 12
},
"Field3": 13,
"Field4": 14,
"Field5": 15
},

{
"geo_position": {
"Field1": 21,
"Field2": 22
},
"Field3": 23,
"Field4": 24,
"Field5": 25
}
]
}

// The code is also preety simple.

JFlat flatMe = new JFlat(jsonString);
flatMe
.json2Sheet()
.headerSeparator("/")
.write2csv("test.csv");

// This will write the result to test.csv file.

// Equivalent CSV representation :


results/Field3,results/Field4,results/Field5,results/geo_position/Field1,results/geo_position/Field2
13.0,14.0,15.0,11.0,12.0
23.0,24.0,25.0,21.0,22.0

关于java - 如何使用 Java 将 json 数组转换为 CSV 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60389205/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com