我的JSON
它有视频,pdf,笔记。我想分别显示不同类型的资源。
任何帮助都会很棒。 我没有使用任何库
{
"results":[
{
"id":136,
"resType":"Videos",
"resLink":"DwRTefPNYOQ",
"resName":"Video",
"canDelete":false,
"canEdit":false,
"canApprove":false
},
{
"id":180,
"resType":"Reference Videos",
"resLink":"RCzulW_kGMk",
"resName":"Vedic Age in India & Contribution to Culture by Mocomi Kids",
"canDelete":false,
"canEdit":false,
"canApprove":false
},
此处重复视频
{
"id":181,
"resType":"Reference Videos",
"resLink":"4l5VRDau4f8",
"resName":"Ancient India's Contributions to the World by Ancient Discoveries",
"canDelete":false,
"canEdit":false,
"canApprove":false
},
{
"id":557,
"resType":"Mind Maps",
"resLink":"upload/33/mind map 2 .pdf",
"resName":"MIND MAP 2",
"canDelete":false,
"canEdit":false,
"canApprove":false
},
{
"id":558,
"resType":"Fill in the blanks",
"resLink":"454",
"resName":"Fill in the blanks",
"canDelete":false,
"canEdit":false,
"canApprove":false
},
{
"id":559,
"resType":"True or False",
"resLink":"455",
"resName":"True or False",
"canDelete":false,
"canEdit":false,
"canApprove":false
},
{
"id":561,
"resType":"Multiple Choice Questions",
"resLink":"457",
"resName":"Multiple Choice Questions ",
"canDelete":false,
"canEdit":false,
"canApprove":false
},
{
"id":567,
"resType":"Mind Maps",
"resLink":"upload/33/mindmap 1.pdf",
"resName":"MIND MAP 1",
"canDelete":false,
"canEdit":false,
"canApprove":false
}
],
"status":"OK"
}
SecondActivity.java
//some code
new DownloadJSON().execute();}
private class DownloadJSON extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
world = new ArrayList<Details>();
jsonobject = JSONfunctions
.getJSONfromURL(url);
try {
// Locate the NodeList name
jsonarray = jsonobject.getJSONArray("results");
for (int i = 0; i < jsonarray.length(); i++) {
jsonobject = jsonarray.getJSONObject(i);
Details results = new Details();
results.setResType(jsonobject.optString("Videos"));
results.setResName(jsonobject.optString("Videos"));
results.setResLink(jsonobject.optString("subject"));
// results.setTopic(jsonobject.optString("topic"));
results.setId(jsonobject.getInt("id"));
//results.setFlag(jsonobject.optString("flag"));
// world.add(results);
}
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
} }
}