I'm parsing a JsonObject
with gson library
using maven dependencies
but I can not have a map containing the keys and values.
I tried with the keyset method but it does not find the correspondence with the value (null pointer exception error) the JSONArray fields reprensent the array that i want to get but currentJsonObject.get("fields")
return an object
that i cant parse to get the other key values.
this is the result of object which i get it from the object return by get("fields")
To summarize I want to parse the JSONArray fields
and retrieve
the value key from this array
JsonReader jsonReader = new JsonReader(new InputStreamReader(new FileInputStream("filename"), StandardCharsets.UTF_8));
jsonReader.beginArray();
Gson gson = new GsonBuilder().create();
Collection<String> list ;
Collection<String> keys ;
BasicDBObject map = new BasicDBObject();
while (jsonReader.hasNext()) {
JSONObject currentJsonObject = gson.fromJson(jsonReader,
JSONObject.class);
System.out.println(currentJsonObject.get("fields"));
}
jsonReader.close();
Json :