我有一个json文件,其格式不像我预期的那样。当我使用CDL将此json文件转换为csv文件时,它的格式不正确,因为我正在将JSONObject转换为JSONArray。
我想更改JSON文件的格式,以便我不必将JSONObject更改为JSONArray。
现有文件格式 -
{"CampaignID":1,"Name":"Halloween Deals","Status":"Sent"}
{"CampaignID":2,"Name":"New Year Deals Campaign 2","Status":"Sent"}
我希望它如何
{"Campaigns":[{"CampaignID":1,"Name":"Halloween Deals","Status":"Sent"},
{"CampaignID":2,"Name":"New Year Deals Campaign 2","Status":"Sent"}]}
我正在提取一个包含广告系列列表的json文件CamapignList.json。该文件包含每个广告系列详细信息的REST API链接。因此,我正在循环遍历CampaignList.json文件中的广告系列数量,并将详细信息写入另一个文件CamapignDetail.json,格式不正确。
JSONObject jObj = new JSONObject(result);
JSONArray items = jObj.getJSONArray("Items");
for (int i=0; i<items.length(); i++)
{
JSONObject cObj = items.getJSONObject(i);
String campaign_url = "rest.xyz.com/v1/Campaigns/…;
System.out.println(camp_url);
HttpGet reqst = new HttpGet(camp_url);
HttpResponse res= client.execute(req);
BufferedReader rd = new BufferedReader (new InputStreamReader(resp.getEntity().getContent()));
PrintWriter wr = new PrintWriter(new FileWriter(camp_file, true));
wr.println(rd.readLine());
}