How to take String JSON values into HashMap

Keka Bron :

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.

RAJKUMAR NAGARETHINAM :

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);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=104826&siteId=1