그래서이 PHP 파일은 JSONArray를 반환합니다.PHP에서 Android로 JSONArray를 조작하는 방법
[
{
"name": "SAMPLE NAME 1",
"number": "12345",
"entity": "User"
},
{
"name": "SAMPLE NAME 2",
"number": "67890",
"entity": "Admin"
}
]
내 안드로이드 앱에 안드로이드 용을 사용하고 있습니다. 나는 그 이름들을 따로 따로 보여줄 토스트를 보여주고 싶다.
이 내 안드로이드 코드 :
StringRequest stringReq = new StringRequest(Request.Method.POST, "http://myfile.php", new Response.Listener<String>()
{
@Override
public void onResponse(String response) {
try {
JSONObject json = new JSONObject(response);
Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
작동하지 않는 점을 말씀해 주시겠습니까? – WasteD
귀하의 응답은 json 배열이 아닌 json 배열입니다. –
[안드로이드에서 JSON을 구문 분석하는 방법] 가능한 복제본 (https://stackoverflow.com/questions/9605913/how-to-parse-json-in-android) – UltimateDevil