jeudi 13 août 2015

Parse Json into a Map in Java

I have a json whose structure can vary in terms of number of nested levels. Like some of the key might have a json object, some of the key might have json object inside a json object. So any key can have a json object (of different depth) or a String as its value. For example,

{
 k1: v1,
 k2: {
      k21: {
           k211: v211,
           k212: v212
           },
      k22: {
           k221: v221,
           k222: v222
           }
     },
 k3: {
      k31: v31
     }
}

Note that k1, k2, k3 have value different levels of json objects (depth of json objects vary) as their values.

I need to parse the above json into a map of key and values like below,

<k1, v1>,
<k211, v211>,
<k212, v212>,
<k221, v221>,
<k222, v222>,
<k31, v31>

How can we parse them like that in java?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire