Suppose in this case I have a table / list such as n = 3, but n can be unlimited.
groupid answerid1 answerid2 answerid(n)
1 3 6 8
1 3 6 9
1 4 7
2 5
and I want to create a parent / child json tree, e.g. using java. (I used GSON)
{
data: [
{
groupid: 1,
children: [
{
answerid1: 1,
children: [
{
answerid2:3,
children: [
{
answerid3:6,
children: [
{answerid4: 8},
{answerid4: 9}
]
}
}, {
answerid2: 4,
children: [
{answerid3:7}
]
}
]
},
{
groupid1: 2,
children: [
{ answerid2: 5}
]
}
]
}
what will be the code / steps for this. I looked through a lot of tags, but mostly people print the output, rather than building a hashmap / ArrayList for GSON recursively for analysis and writing to the API. another point at which each identifier has other data associated with it that should be included in json output. for example, instead of {groupid: 1}, you would need this {groupid: 1, text = toyota}.
any help is much appreciated as I am pretty new to java as I come from the SAS background.
I get data like this (just a list matrix) Toyota, Gas, Compact, Corolla
Toyota, Gas, Compact, Camry Toyota, Hybrid, Compact, Prius Honda, Gas, Compact, CivicIf necessary, I can REFORM DATA into two tables
parentId parText answerId
1 Toyota 1 1 Toyota 2 1 Toyota 3 2 Honda 4answerId level answerTextid answerText
1 1 1 Gas 1 2 2 Compact 1 3 3 Corolla 2 1 1 Gas 2 2 2 Compact 2 3 4 Camry ...Then I need to make it a tree (a nested result similar to JSON readings with parent / child elements - just as if you were creating a file system directory)
one other tin that I would like to make is for each car a run like varialbe ({answerid3: 4, text = Corolla, run = 38}., but also, if I walk through a tree, give the average mile for the branch As they say in Toyota, Gas, Compact mileage will be avg (Camry, Corolla)
, - . , (hashmap)
{"data":[{"id":1,"children":
[{"id": 2,"children":
[{"id": 3 ,"children":
[{"id": 4,"name":"Prius"}],"name":"Compact"}],"name":"Hybrid"},
{"id":5,"children":
[{"id":3,"children":
[{"id":7,"MPG":38, "name":"Corolla"},
{"id":8,"MPG":28,"name":"Camry"}],"name":"Compact"}],"name":"Gas"}],"name":"Toyota"},
{"id":9, "children":
[{"id":10,"children":
[{"id":3 ,"children":
[{"id":11 ,"name":"Civic"}],"name":"Compact"}],"name":"Gas"}],"name":"Honda"}]}