I’ve got 2 java Lists (Arraylists) of Floats, ListA and ListB of x and y coordinated which look like:
ListA = 10.1, 17.3, 30.0
ListB = 1.4, -14.7, 5.1
and I want to create a json object such that the two arraylists are consolidated into a single json object as:
[ { label: "A", data: [ [10.1, 1.4], [17.3, -14.7], [30.0, 5.1] ] }]
that I can plot using flot.
I’ve been looking at the Gson lib but I can’t see a concise way to do this – is there a simpler way than setting up loops for each key and manually appending “[ { …” etc ?
Thanks!
I think I understood what you need.
You are tryng to create the object structure to create the JSON in the format that you showed. Am I right? So, try something like:
The lists of arrays of floats needs to be populated as (using listA and listB):
To generate JSON (in another class):