I am using GSON in my Java project to encode data ( that are fetched from database and stored into a String array ) in JSON format. Everything looks OK but the problem is with the size of String. For example I have the following String array:
String [] data = new String[12];
Suppose my String array contains the following data: {"ABC", "DEF", "GH", "IJ"}
Then the encoded JSON data are: ["ABC", "DEF", "GH", "IJ", "\u0000", null, null, null, null, null, null]
The number of null value in the JSON data is depends on the number of data available in my String array.
As the data is retrieved from database so I can't declare a specific size for my String array.
I am using the following code to encode String data into JSON format.
Gson gs = new Gson();
gs.toJson(data); //data String array contains data from database
Can anyone tell me how can I skip/remove those null value from my JSON data?
dataarray is always defined as 12 in size? When you load the data form the database the excess capacity is padded with null? What about the\u0000String?data[index] = "\0". maybe\u000is added for this.