K
K
Kentaro232020-06-20 23:00:39
Java
Kentaro23, 2020-06-20 23:00:39

How to remove unnecessary map and MyArrayList tags from json?

When generating json, map and MyArrayList tags appear, how can json be generated without these tags?
The output was supposed to be this format.
{
"count":123,
"records":[
{
"name":"tr.wav",
"dateCreate":"2010-01-01 00:00:00"
},
{
"name":"tret.wav ",
"dateCreate":"2010-02-01 00:00:00"
}
]
}

private String getStr(Data changeData) throws Exception
  {
    List<File> fileList= null;
    int maxNumber = 123;
    
    fileList = getFiles();
       
    ObjectMapper mapper = new ObjectMapper();
  
    JSONObject parentData = new JSONObject();
    JSONArray audioData = new JSONArray();
    Gson gson = new Gson();
    try
    {
      parentData.put("countFiles", fileList.size());
    }
    catch (JSONException e)
    {
      e.printStackTrace();
    }
    String json =null;
    for (File file : fileList)
    {
      
      audioData.put(getFile(file));
       
      countTries++;
    }
  
    parentData.put("records2", audioData);
    //return mapper.writeValueAsString(parentData);
    return new Gson().toJson(parentData);
  //mapper.writeValueAsString(parentData);
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mayton2019, 2020-06-20
@mayton2019

1) What is data? Why do you write class names with a small letter? It seems to be a trifle, but it annoys the reader of your code. There is a suspicion of an error or incorrect copy-paste.
2) It is very difficult to understand what you wanted to get at the output. Draw a sample of the desired document in Json and you will be helped faster.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question