我試圖解析這個JSON使用gson,但我不能。 任何人都可以幫助我解析這個JSON使用gson?使用Gson嵌套的Json解析
JSON:
{
"status": "ok",
"results": {
"favourites": [
{
"id": "UB3172",
"name": "Masdar Headquarters"
},
{
"id": "UB1438",
"name": "Guggenheim Abu Dhabi on Saadiyat Island"
},
{
"id": "UB4838",
"name": "Watani Residential Development in Abu Dhabi - 600 Villas and 48 Buildings"
},
{
"id": "UB4795",
"name": "Two Mosques in Mohammed Bin Zayed City"
},
{
"id": "UB1274",
"name": "2 Workers Residential City at Al Ain Industrial City"
}
]
}
}
我想這一個JSON解析器類:
public class ProjectList {
public String status;
public String results;
public class Favourites{
public String id;
public String name;
}
}
在MainActivit
Reader reader = new InputStreamReader(result);
Gson gson=new Gson();
List<ProjectList.Favourites> fav=new ArrayList<ProjectList.Favourites>();
fav=Arrays.asList(gson.fromJson(reader, ProjectList.Favourites.class));
你有沒有嘗試過。 –
是的..我已經試過 – Ansar
你可以發佈你的代碼。 –