I am trying to output a list in JSON formatting but it's not coming out quite the way I want it.
Here is the output:
{
"songMap": [
{
"SID": "699",
"SDID": "1079287588763212246"
},
{
"SID": "700",
"SDID": "1079287588763212221"
},
{
"SID": "701",
"SDID": "1079287588763212230"
}
]
}
Here is what I would like it to look like:
[
{
"SID": "699",
"SDID": "1079287588763212246"
},
{
"SID": "700",
"SDID": "1079287588763212221"
},
{
"SID": "701",
"SDID": "1079287588763212230"
}
]
I don't need nor want the intermediate array, im not sure why it's being added. I have a custom class as follows:
public class songID {
public int SID;
public String SDID;
public songID() {}
public songID(int key, String value) {
this.SID = key;
this.SDID = value;
}
}
This is how it's being serialized:
Gson gson = new Gson();
String json = gson.toJson(songMap);
If I print out the string json ,it looks the way I want it to. However the server is adding the additional "SongMap." Here is how my variable is declared at the top of the class:
private List<songID> songMap;
.....
songMap = new ArrayList<songID>();