Skip to content

Instantly share code, notes, and snippets.

@donrokzon
Last active July 16, 2018 10:35
Show Gist options
  • Save donrokzon/d5221a12aeb1c69fcc0cf6c859278a5d to your computer and use it in GitHub Desktop.
Save donrokzon/d5221a12aeb1c69fcc0cf6c859278a5d to your computer and use it in GitHub Desktop.
gson parsing
////////////////
[{
"avatar": "https:\/\/s3.amazonaws.com\/uifaces\/faces\/twitter\/calebogden\/128.jpg",
"last_name": "Bluth",
"id": 1,
"first_name": "George"
}, {
"avatar": "https:\/\/s3.amazonaws.com\/uifaces\/faces\/twitter\/josephstein\/128.jpg",
"last_name": "Weaver",
"id": 2,
"first_name": "Janet"
}, {
"avatar": "https:\/\/s3.amazonaws.com\/uifaces\/faces\/twitter\/olegpogodaev\/128.jpg",
"last_name": "Wong",
"id": 3,
"first_name": "Emma"
}]
if (dataArray.length() > 0) {
List<Profile> peoples = Arrays.asList(gson.fromJson(dataArray.toString(), Profile[].class));
for (Profile people : peoples) {
Log.i("TAG", "setData: " + people.getFirstName());
}
}
//////////////////////////
"data": [{
"slot_num": "10",
"slot_starting_time": "11:30:00",
"slot_ending_time": "11:40:00",
"consulted": "0",
"fullname": "don kulkarni"
}, {
"slot_num": "20",
"slot_starting_time": "20:30:00",
"slot_ending_time": "20:50:00",
"consulted": "0",
"fullname": "sujeesh"
}]
Type listType = new TypeToken<List<ConsultationData>>() {}.getType();
List<ConsultationData> targetObject = gson.fromJson(data.getString("data"), listType);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment