次のコードはうまく機能します(!)、私はそれを独自の関数に移しましたが、json変換されたArray(最終行)から戻ってきません。何をwronngしていますか? 「未声明」:Javaでjson変換された配列からaを返すには?
public Array jsonToArray(String json) {
JSONObject myjson = null;
try {
myjson = new JSONObject(json);
} catch (JSONException e) {
e.printStackTrace();
}
JSONArray the_json_array = null;
try {
the_json_array = myjson.getJSONArray("profiles");
} catch (JSONException e) {
e.printStackTrace();
}
int size = the_json_array.length();
ArrayList<JSONObject> arrays = new ArrayList<JSONObject>();
for (int i = 0; i < size; i++) {
JSONObject another_json_object = null;
try {
another_json_object = the_json_array.getJSONObject(i);
} catch (JSONException e) {
e.printStackTrace();
}
arrays.add(another_json_object);
}
JSONObject[] jsons = new JSONObject[arrays.size()];
arrays.toArray(jsons);
return Array jsons;
}
私はイムはエラーを取得...問題のタイプだと思いますが、JAVAで完全に新しいイム。意味と解決策は何ですか?
'return Array jsons;'は有効な構文ではありません... 'return jsons;'はありますが、それがあなたの望むものであるかどうかは不明です –
上記のコードはコンパイルされません –
実際にはコードはありません、 "うまく動作する"実際に実行されない限り –