3

I have an org.bson.Document that I can convert into a JSON:

for (Document dc : list) {
        String doc = dc.toJson();
    }

And the String looks like:

{
"_id": "C:\\Users\\santi\\Desktop\\2010-documents.biased\\99\\2010-99-086.html", 

"data": {
        "german": 1, 
        "metadata": 1, 
        "inform": 20, 
        "almanac": 1,
         etc etc
        }
 }

I'm stucked at figuring how to access to the "data" field and get all the key-value values and store them into a HashMap or Map. I thought about spliting the array and getting some substrings etc but doesn't seem like a good way.

Keka Bron
  • 419
  • 4
  • 17

1 Answers1

1

Please use like this :

HashMap<String,Integer> result = new com.fasterxml.jackson.databind.ObjectMapper().readValue(json, HashMap.class);

Or

Gson GSON = new com.google.gson.Gson();

HashMap<String,Integer> result = GSON.fromJson(json, HashMap.class);
Vikas
  • 6,868
  • 4
  • 27
  • 41
RAJKUMAR NAGARETHINAM
  • 1,408
  • 1
  • 15
  • 26