안녕 내 PHP 파일의 json_encoded 출력은 다음과 같습니다 내 안드로이드 코드에서은 JSONArray에서 다차원 배열을 얻기 (안드로이드 PHP)
[{"index":1,"questions":"If the number of berths in a train are 900 more than one-fifth of it, find the total berths in the train?","options":["1145","1130","1135","1125","1120"],"answers":"1125","useranswers":"1145"}]
, 나는 2 차원 배열에서 "옵션"을 저장해야합니다.
JSONArray jArray = new JSONArray(result);
JSONObject json_data=null;
JSONArray options_array=null;
JSONArray option_ids_array=null;
no_of_questions=jArray.length();
questions=new String[no_of_questions];
question_id=new String[no_of_questions];
options=new String[no_of_questions][];
option_ids=new String[no_of_questions][];
for(int i=0;i<no_of_questions;i++){
json_data = jArray.getJSONObject(i);
questions[i] =json_data.getString("questions");
question_id[i] =json_data.getString("question_ids");
Log.i("Question ids",""+question_id[i]);
options_array=json_data.getJSONArray("options");
option_ids_array=json_data.getJSONArray("option_ids");
options[i]=new String[options_array.length()];
option_ids[i]=new String[options_array.length()];
for(int j=0;j<options_array.length();j++){
options[i][j]=options_array.get(j).toString();
option_ids[i][j]=option_ids_array.get(j).toString();
}
}
어떻게 수행하나요? 제발 도와주세요, 저는 안드로이드를 처음 사용합니다.
http://www.json.org/javadoc/org/json/JSONArray.html – nnhthuan
무엇을 시도 했습니까? 어디서 봤니? 안드로이드에 익숙하지 않다면 연구를하지 않을 이유가 없다. –
이것은 안드로이드와 아무런 관련이 없다. org.json 라이브러리를 보라. 'JSONArray'를 조작해야합니다. – tbruyelle