package agriculture_implement.util;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import java.util.Map;
public class JsontoMap {
public static Map<String, Object> json2map(String str_json){
Map<String, Object> res = null;
try {
Gson gson = new Gson();
res = gson.fromJson(str_json, new TypeToken<Map<String, Object>>() {
}.getType());
} catch (JsonSyntaxException e) {
e.printStackTrace();
}
return res;
}
}
需要引入的包:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>