android:json파싱하기
json파싱하기
차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판이전 판 | |||
| android:json파싱하기 [2025/04/23 23:24] – 이거니맨 | android:json파싱하기 [2025/04/23 23:37] (현재) – 이거니맨 | ||
|---|---|---|---|
| 줄 306: | 줄 306: | ||
| <code kotlin> | <code kotlin> | ||
| + | // 스트링에서 JSON 배열을 돌려주는 함수 | ||
| fun getJsonAnswerText(jsonText : String) : ArrayList< | fun getJsonAnswerText(jsonText : String) : ArrayList< | ||
| - | val jsonArray = JSONArray(jsonText) | + | |
| + | | ||
| - | | + | |
| - | | + | |
| - | val jsonObject = jsonArray[i] as JSONObject | + | val jsonObject = jsonArray[i] as JSONObject |
| - | | + | |
| - | text = jsonObject.optString(" | + | text = jsonObject.optString(" |
| - | correctness = jsonObject.optString(" | + | correctness = jsonObject.optString(" |
| - | index = jsonObject.optString(" | + | index = jsonObject.optString(" |
| - | | + | |
| - | | + | |
| + | } | ||
| + | |||
| + | return textArray | ||
| + | }catch (e: JSONException) { | ||
| + | // TODO Auto-generated catch block | ||
| + | e.printStackTrace() | ||
| } | } | ||
| + | | ||
| + | // 아래 코드는 만약에 에러가 날 경우에만 돌려주는 더미 배열이다. | ||
| + | val textArray = ArrayList< | ||
| return textArray | return textArray | ||
| + | |||
| } | } | ||
android/json파싱하기.1745418262.txt.gz · 마지막으로 수정됨: 저자 이거니맨
