Convert JSON to Map

后端 未结 17 3139
天涯浪人
天涯浪人 2020-11-22 10:20

What is the best way to convert a JSON code as this:

{ 
    \"data\" : 
    { 
        \"field1\" : \"value1\", 
        \"field2\" : \"value2\"
    }
}
         


        
17条回答
  •  死守一世寂寞
    2020-11-22 10:58

    Using the GSON library:

    import com.google.gson.Gson;
    import com.google.common.reflect.TypeToken;
    import java.lang.reclect.Type;
    

    Use the following code:

    Type mapType = new TypeToken>(){}.getType();  
    Map son = new Gson().fromJson(easyString, mapType);
    

提交回复
热议问题