我的JSON响应看起来像
[{"order":-1,"artist":[{"name":"Hey"}]},...]
如何使用GSON从name
对象获取artist
?
我试过用这样的东西
private String getArtistName(){
...
Type type = new TypeToken<List<Order>>() {}.getType();
List<Order> details = gson.fromJson(MyJSONresponse, type);
for (Order order : details) {
if (order.order == -1) {
String artistName = // I don't know what to enter here
return artistName;
}
}
return null;
}
private class Order{
int order;
List<Artist> artist = new ArrayList<Artist>();
}
pricate class Artist{
String name;
}
谢谢!
答案 0 :(得分:0)
class MyClass {
int order;
List<Artist> artist;
}
class Artist {
String name;
}
MyClass myClass = new Gson().fromJson(myJsonString, MyClass[].class);
myClass.artist.get(0).name;