如何在retrofit2中获取json

时间:2017-02-22 18:25:39

标签: android json

我正在制作和Android应用程序,其中我从api获取json数据但我不知道如何获取json数据,getter和setter类我们传递serialize。 这是我的json数据{"status":true,"message":"Notifications fetched.","data":[{"id":"69","type":"liked","text":"Sandip Ghosh liked your photo.","for_userid":"56","from_userid":"55","for_image":"54","seen":"0","username":"sandip","firstname":"Sandip","lastname":"Ghosh","imgname":""},{"id":"64","type":"liked","text":"Sandip Ghosh liked your photo.","for_userid":"56","from_userid":"55","for_image":"54","seen":"0","username":"sandip","firstname":"Sandip","lastname":"Ghosh","imgname":""},{"id":"63","type":"liked","text":"Sandip Ghosh liked your photo.","for_userid":"56","from_userid":"55","for_image":"54","seen":"0","username":"sandip","firstname":"Sandip","lastname":"Ghosh","imgname":""},{"id":"62","type":"commented","text":"Sandip Ghosh commented onyour photo.","for_userid":"56","from_userid":"55","for_image":"54","seen":"0","username":"sandip","firstname":"Sandip","lastname":"Ghosh","imgname":""},{"id":"61","type":"liked","text":"Sandip Ghosh liked your photo.","for_userid":"56","from_userid":"55","for_image":"53","seen":"0","username":"sandip","firstname":"Sandip","lastname":"Ghosh","imgname":""},{"id":"27","type":"Follow","text":"Sandip Ghosh started following you","for_userid":"56","from_userid":"55","for_image":"0","seen":"1","username":"sandip","firstname":"Sandip","lastname":"Ghosh","imgname":""}]}

1 个答案:

答案 0 :(得分:0)

把你的整个json放到http://pojo.sodhanalibrary.com/ 这将为您创建模型。 它将毫不费力地创建Serializable模型。 然后使用这些模型获取值。 有关以下教程的更多信息 https://github.com/codepath/android_guides/wiki/Consuming-APIs-with-Retrofit