I have three String[][] arrays that can be of different lengths. The second length is always fixed, and has length of 6, but the first length can differ between 0 and 6.
I want to create a Json-string containing the data of all of these String arrays. As of now it's hard coded, but i realize I'll get in to trouble once the lengths isn't fixed anymore...
travelgl1.put("Duration", str1[0][0]);
travelgl1.put("Walking time", str1[0][1]);
travelgl1.put("Direction", str1[0][2]);
travelgl1.put("Departure", str1[0][3]);
travelgl1.put("Arrival", str1[0][4]);
travelgl1.put("End station", str1[0][5]);
So basically I want a dynamic loop that loops through the String arrays and adds all the data in that array.
Is there any easy way to do this? I want all three json objects (from the three String arrays) to be compiled in to one big json string in the end.
I want the end result to look like this:
[ { "String array 1" : [ { "Duration" : "33", "Walking time" : "8", "Direction" : "Åkeshov", "Departure" : "09:39", "Arrival" : "10:43", "End station" : "Sollentuna" }, { "Duration" : "37", "Walking time" : "8", "Direction" : "Alvik", "Departure" : "09:43", "Arrival" : "10:51", "End station" : "Sollentuna" }, { "Duration" : "34", "Walking time" : "8", "Direction" : "Alvik", "Departure" : "09:53", "Arrival" : "10:58", "End station" : "Sollentuna" }, { "Duration" : "36", "Walking time" : "8", "Direction" : "Åkeshov", "Departure" : "09:59", "Arrival" : "11:06", "End station" : "Sollentuna" }, { "Duration" : "33", "Walking time" : "8", "Direction" : "Åkeshov", "Departure" : "10:09", "Arrival" : "11:13" } ] }, { "String array 2" : [ { "Duration" : "54", "Walking time" : "13", "Direction" : "Farsta strand", "Departure" : "09:43", "Arrival" : "11:13", "End station" : "Sollentuna" }, { "Duration" : "47", "Walking time" : "13", "Direction" : "Gullmarsplan", "Departure" : "09:50", "Arrival" : "11:13", "End station" : "Sollentuna" }, { "Duration" : "45", "Walking time" : "13", "Direction" : "Gullmarsplan", "Departure" : "10:00", "Arrival" : "11:21", "End station" : "Sollentuna" }, { "Duration" : "42", "Walking time" : "13", "Direction" : "Gullmarsplan", "Departure" : "10:10", "Arrival" : "11:28", "End station" : "Sollentuna" }, { "Duration" : "45", "Walking time" : "13", "Direction" : "Gullmarsplan", "Departure" : "09:30", "Arrival" : "10:51", "End station" : "Sollentuna" } ] }, { "String array 3" : [ { "Duration" : "31", "Walking time" : "12", "Direction" : "Hässelby strand", "Departure" : "09:45", "Arrival" : "10:51", "End station" : "Sollentuna" }, { "Duration" : "31", "Walking time" : "12", "Direction" : "Alvik", "Departure" : "09:52", "Arrival" : "10:58", "End station" : "Sollentuna" }, { "Duration" : "33", "Walking time" : "12", "Direction" : "Åkeshov", "Departure" : "09:58", "Arrival" : "11:06", "End station" : "Sollentuna" }, { "Duration" : "30", "Walking time" : "12", "Direction" : "Åkeshov", "Departure" : "10:08", "Arrival" : "11:13", "End station" : "Sollentuna" }, { "Duration" : "31", "Walking time" : "12", "Direction" : "Hässelby strand", "Departure" : "10:15", "Arrival" : "11:21", "End station" : "Sollentuna" } ] } ]
So, what I really want is a dynamic way of creating a Json string depending on the length of the string array.
Thanks in advance!