3
嗨我試圖從我的JSON到我的'結果'數組中獲取所有'ID'值。libgdx Json解析
我並沒有真正理解libgdx的json類是如何工作的,但我知道json是如何工作的。
這裏是JSON:http://pastebin.com/qu71EnMx
這裏是我的代碼:
Array<Integer> results = new Array<Integer>();
Json jsonObject = new Json(OutputType.json);
JsonReader jsonReader = new JsonReader();
JsonValue jv = null;
JsonValue jv_array = null;
//
try {
String str = jsonObject.toJson(jsonString);
jv = jsonReader.parse(str);
} catch (SerializationException e) {
//show error
}
//
try {
jv_array = jv.get("table");
} catch (SerializationException e) {
//show error
}
//
for (int i = 0; i < jv_array.size; i++) {
//
try {
jv_array.get(i).get("name").asString();
results.add(new sic_PlayerInfos(
jv_array.get(i).get("id").asInt()
));
} catch (SerializationException e) {
//show error
}
}
這裏是我得到錯誤:上jv_array.size '空指針'
這個例子應該可能被添加到LibGDX wiki中。 – twiz