我有一个JSON文件
{
"name": "re2",
"count": 1806,
"frequency": "realtime",
"version": 5,
"newdata": true,
"lastrunstatus": "success",
"lastsuccess": "Fri May 30 2014 06:02:41 GMT+0000 (UTC)",
"results": {
"collection1": [
{
"Title": {
"href": "http://www.realestate.com.au/project-spec+property+%e2%80%93+helio+apartments-vic-north+melbourne-600004887",
"text": "93 Flemington Road, North Melbourne, Vic 3051"
},
"image": {
"href": "http://www.realestate.com.au/project-spec+property+%e2%80%93+helio+apartments-vic-north+melbourne-600004887",
"alt": "93 Flemington Road, North Melbourne, Vic 3051",
"src": "http://i2.au.reastatic.net/345x200/3a7e58fe3aefa7fd373c1b9c9879d648257dc0e7c8d35c6b7a19d261bffeff28/main.jpg"
},
"price": "$700,000 - $770,000",
"title2": {
"href": "http://www.realestate.com.au/project-spec+property+%e2%80%93+helio+apartments-vic-north+melbourne-600004887",
"text": "93 Flemington Road, North Melbourne, Vic 3051"
}
},
{
"Title": {
"href": "http://www.realestate.com.au/project-redmond+park-vic-carlton+north-600002807",
"text": "300 Pigdon Street, Carlton North, Vic 3054"
},
"image": {
"href": "http://www.realestate.com.au/project-redmond+park-vic-carlton+north-600002807",
"alt": "300 Pigdon Street, Carlton North, Vic 3054",
"src": "http://i2.au.reastatic.net/345x200/c22712b2c40db6e8017ebc6f677c9835991e3e1ab9431cfe28d0ab8ea0af43e3/main.jpg"
},
"price": "$830,000 - $880,000",
"title2": {
"href": "http://www.realestate.com.au/project-redmond+park-vic-carlton+north-600002807",
"text": "300 Pigdon Street, Carlton North, Vic 3054"
}
},
{
"Title": {
"href": "http://www.realestate.com.au/property-house-vic-kensington-116973739",
"text": "60 WOLSELEY PARADE, Kensington, Vic 3031"
},
"image": {
"href": "http://www.realestate.com.au/property-house-vic-kensington-116973739",
"alt": "60 WOLSELEY PARADE, Kensington, Vic 3031",
"src": "http://i4.au.reastatic.net/355x265/e026805577c810c6df722c171a00786f4510cb959390375d589e2d1d90ef2461/main.jpg"
},
"price": "SOLD $1,360,000",
"title2": {
"href": "http://www.realestate.com.au/property-house-vic-kensington-116973739",
"text": "60 WOLSELEY PARADE, Kensington, Vic 3031"
}
},
我在这个文件中试过了很多在线JSON到CSV转换器,它永远无法正常转换。
我想要一个CSV文件 标题,href,文本,图像,href,alt,src,价格
由于文件的复杂性,我在网上任何教程都没有运气。
答案 0 :(得分:1)
通常,自动将JSON自动转换为CSV是不可能的,因为一个是对象图,另一个本质上是一个表。这就像尝试将立方体转换为圆形一样。
为了使这个问题更加复杂,你的JSON似乎并不是同质的。最明显的是,第一个条目没有title2实例。为了解决这个问题,我将其分解为以下步骤:
从您的示例JSON中可以立即将它全部读入内存,或者是否需要将其分解,一次转换一个项目。我怀疑你会找到一个能为你做到这一点的在线工具,因为你的JSON似乎不连贯,你的需求非常具体。
答案 1 :(得分:0)
我刚刚发布了一个模块,可以在Node.js中轻松完成此过程
var jsonexport = require('jsonexport');
var contacts = [{
name: 'Bob',
lastname: 'Smith',
family: {
name: 'Peter',
type: 'Father'
}
},{
name: 'James',
lastname: 'David',
family:{
name: 'Julie',
type: 'Mother'
}
},{
name: 'Robert',
lastname: 'Miller',
family: null,
location: [1231,3214,4214]
},{
name: 'David',
lastname: 'Martin',
nickname: 'dmartin'
}];
jsonexport(contacts,function(err, csv){
if(err) return console.log(err);
console.log(csv);
});
答案 2 :(得分:0)
有一个名为json2flat的图书馆 它的作用是采用复杂的JSON文档并将其转换为CSV格式。
所以你需要做的是将你的java对象转换为JSON格式。之后 你需要将生成的JSON传递给库,它返回一个2D 表示JSON,您也可以从中获取csv。
这个图书馆并不成熟,但仍然很有前途。 你应该试一试。