我有一个与此类似的csv文件
"name.firstName","name.givenName","name.DisplayName","phone.type","phone.value"
"john","maverick","John Maverick","mobile","123-123-123"
"jim","lasher","Jim Lasher","mobile","123-123-123"
我想将第2行和第3行转换为JSON对象。使用第一行作为标题。所以结果将是
[
{
"name": {
"firstName": "john",
"givenName": "maverick",
"DisplayName": "John Maverick"
},
"phone": {
"type": "mobile",
"value": "123-123-123"
}
},
{
"name": {
"firstName": "john",
"givenName": "maverick",
"DisplayName": "John Maverick"
},
"phone": {
"type": "mobile",
"value": "123-123-123"
}
]
知道如何实现这个目标吗?
答案 0 :(得分:3)
这是一个可以帮助您的Java库。 http://www.jonathanhfisher.co.uk/playpen/csv2json/index.htm
这是一个对您有用或可能没用的JavaScript库。 http://www.cparker15.com/code/utilities/csv-to-json/
最后,这是一个可能有用的过去答案。我喜欢OpenCSV解决方案。但是,您可以使用杰克逊代替JAXB。 Converting an CSV file to a JSON object in Java