I have a JSON
like below:
{
"username": {
"A1": {
"L1": "usernameL1",
"V1": "usernameV1"
},
"A2": {
"L2": "usernameL2",
"V2": "usernameV2"
}
},
"password": {
"L": "passwordL",
"V": "passwordV"
},
"loginButton": {
"L": "loginButtonL",
"V": "loginButtonV"
}
}
I have to create a hashmap as HashMap<String, HashMap<String,String>>
such that the outer most key is key for outer hashmap and values in itself will be a json.
In this case there will be total of 3 key
, value
pair and for first element i.e username there will be two key value pair for value.
How can I check if json has nested json
in itself or not. I have to write a generic code which can case it will be independent of key
name and all.
I tried below code but it does not help:
jsonHierarchy = JSON.parse(data);
for(var json in jsonHierarchy){
j = jsonHierarchy[json]
for(var k in j){
console.log(k)
var sub_key = k;
var sub_val = json[k];
console.log(" Key: "+sub_key+" Value: "+sub_val);
}
}
Can someone help me with this,
I want to store in hashmap as shown in below image: (first column is key and value is another hashmap as my json)