您首先需要定义几个类:
麦格森
public class MyGson {
private String apiVersion;
private Data data;
public Data getData() {
return data;
}
}
数据
public class Data {
private String updated;
private int totalItems = 0;
private int startIndex = 0;
private int itemsPerPage = 0;
private List<Item> items;
public List<Item> getItems() {
return items;
}
}
物品
public class Item {
private String id;
private String uploaded;
private String updated;
private String uploader;
private String category;
private String title;
private String description;
private Map<Integer, String> content;
public Map<Integer, String> getContent() {
return content;
}
}
看一看,你content
的地图key
是 1,2,3,4,5,6 ....
你可以定义Map<String, String> content
,但因为你所有的键都是整数..
所以现在你可以提取你想要的任何值:
启动器
....
Gson gson = new Gson();
MyGson myGson = gson.fromJson(str, MyGson.class);
List<Item> items = myGson.getData().getItems();
if(items.size()>0){
Item item = items.get(0);
String myStr = item.getContent().get(1);
System.out.println(myStr);
}
输出:
rtsp://r6---sn-cg07lue6.c.youtube.com/CiILENy73wIaGQl1cubZZSUSXxMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp