0
텍스트 파일을 읽고 Android 응용 프로그램에서 JSONObject를 만들려고 시도했지만 텍스트 파일을 문자열로 읽은 후 문자열을 사용하여 JSONObject를 만들 때 JSONException이 발생합니다. . 여기 텍스트 파일에서 JSONObject 만들기
InputStream is = this.getResources().openRawResource(R.raw.quiz);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String jsString = "";
String line = null;
while((line = reader.readLine()) != null){
jsString += line;
}
is.close();
reader.close();
try {
return new JSONObject(jsString);
} catch (JSONException e) {
}
return null;
내가 quiz.txt에서 독서하고있는 텍스트 파일입니다 : 여기
내가 사용하고있는 코드입니다
{"length":3,"questions":[{"questionText":"Is mayonaise an instrument?","answers":["Yes","no","no","no","no"],"correctAnswer":0},{"questionText":"10^2","answers":["1","10","100","1000","over 9000"],"correctAnswer":1},{"questionText":"Dogs Name?","answers":["Barky","Steve","Rex","Daisy","Wormy"],"correctAnswer":3}]}
예외 ('e.getMessage()')에 메시지가 있습니까? –
답변 (숫자)을 따옴표에 넣으려고 했습니까? – Trinimon
e.getMessage()의 값을 확인하고 내 문제가있는 곳을 찾을 수있었습니다. 감사! – GammaGuy