java我想用动态的方式把这个json做成表格式,我怎样才能用安卓来制作呢?
String jsonData="{\"sem1\" :[{\"subname\":\"TOC\",\"subcode\":\"1009\",\"subcredit\":\"6\",\"subgrade\":\"AB\"},{\"subname\":\"DS\",\"subcode\":\"10090\",\"subcredit\":\"5\",\"subgrade\":\"BB\"},{\"subname\":\"TOC\",\"subcode\":\"1009\",\"subcredit\":\"6\",\"subgrade\":\"AB\"}],\"sem2\":[{\"subname\":\"AAS\",\"subcode\":\"111009\",\"subcredit\":\"6\",\"subgrade\":\"AB\"},{\"subname\":\"AE\",\"subcode\":\"103309\",\"subcredit\":\"6\",\"subgrade\":\"DD\"}]}";
这是我的代码:
protected String doInBackground(String... params1) {
try {
jsonObject = new JSONObject(jsondata);
} catch (JSONException e) {
e.printStackTrace();
}
Iterator<String> iter = jsonObject.keys();
while (iter.hasNext()) {
String key = iter.next();
try {
JSONArray jsonArray = jsonObject.getJSONArray(key);
int length = jsonArray.length();
for (int i = 0; i < length; i++) {
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
subname = jsonObject1.getString("subname");
subcode = jsonObject1.getString("subcode");
subcredit = jsonObject1.getString("subcredit");
subgrade = jsonObject1.getString("subgrade");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
return null;
}
# 1 楼答案
创建一个列表视图并向其添加值
获取json值并将其添加到ListContainer中
//上下文、资源、对象
注意:这些边框样式用于绘制边框。类似于box类型的表格形式的xml