This is my input JSON From which I have to fetch interLockingGrids
and store it into ArrayList<ClassType>
. I have searched enough already but didn't find exactly what I want. Is there is any simplest way?
{"entity":"MasterGrid",
"data" :"{\"name\":\"MA_Pune\",
\"coordinates\" : [
{\"lat\":18.553449789265677,\"lng\":73.77419574114515},{\"lat\":18.554232972087224,\"lng\":73.77367002817823},{\"lat\":18.556135000463573,\"lng\":73.77144913093571},{\"lat\":18.555148376025496,\"lng\":73.7700973257704},{\"lat\":18.55309341985624,\"lng\":73.77075145899971},{\"lat\":18.5530421437421,\"lng\":73.77312207276918} ] ,
\"interLockingGrids\": [
{\"name\":\"Test1\",\"type\":\"CLUSTER\",\"coordinates\":[{\"lat\":18.555151666563823,\"lng\":73.7700902617189},{\"lat\":18.556135000463573,\"lng\":73.77144913093571},{\"lat\":18.556135000463573,\"lng\":73.77144913093571},{\"lat\":18.556135000463573,\"lng\":73.77144913093571},{\"lat\":18.556135000463573,\"lng\":73.77144913093571},{\"lat\":18.556135000463573,\"lng\":73.77144913093571}],\"isActive\":true,\"colorCode\":\"#D0983C\"} ,
{\"name\":\"Test2\",\"type\":\"CLUSTER\",\"coordinates\":[{\"lat\":18.5530421437421,\"lng\":73.77312207276918},{\"lat\":18.553449789265677,\"lng\":73.77419574114515},{\"lat\":18.55238201763598,\"lng\":73.7743998478852}],\"isActive\":true,\"colorCode\":\"#8E75B7\"} ] ,
"operation":"GRID_OPERATION",
"description":"Baner_Test",
"submittedBy":"m@abc.com",
"submittedById":4,
"submittedByType":"OPS" }
In a recent project I did something similar:
public List<MyType> parseJsonToListOfMyType(String json) {
Gson gson = new Gson();
JsonArray job = gson.fromJson(json, JsonArray.class);
Type listType = new TypeToken<List<MyType>>(){}.getType();
return gson.fromJson(job, listType);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.