我希望有人能帮助我。我正在尝试解析以下 json 文件:
{
"seminar":[{
"categoryid": "1",
"cpe": "13",
"inventory": [
"Discussion",
"Value x",
"Value y"
],
"teachers": [{
"titel": "Dipl.-Ing.",
"company": "XY",
"name": "Test",
"id": "3"
}]
}]
}
我在解析教师数据时迷失了......
private static final String TAG_TEACHERS = "teachers";
private static final String TAG_TITLE = "title";
for(int i = 0; i < seminar.length(); i++){
JSONObject c = seminar.getJSONObject(i);
teachers = c.getJSONArray(TAG_TEACHERS);
for(int z = 0; z < teachers.length(); z++){
JSONObject d = teachers.getJSONObject(z);
String title = d.getString(TAG_TITLE);
Log.d("JSONParsingActivity", title);
我收到错误 System.err(1010): org.json.JSONException: org.json.JSONObject$1 类型的教师的 Value null 无法转换为 JSONArray。
我做错了什么?正如我从 JSON 文档中了解到的那样,教师是 JSON 数组而不是对象。有人可以帮助我吗?