StringRequest stringRequest = new StringRequest(
Request.Method.POST,
Configs.Login,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
progressDialog.dismiss();
try {
JSONObject obj = new JSONObject(response);
if(!obj.getBoolean("error")){
startActivity(new Intent(getApplicationContext(), MainActivity.class));
finish();
}else{
Toast.makeText(
getApplicationContext(),
obj.getString("message"),
Toast.LENGTH_LONG
).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.dismiss();
Toast.makeText(
getApplicationContext(),
error.getMessage(),
Toast.LENGTH_LONG
).show();
}
}
)
@Override
표시되는 JSON 형식에 오류가 있습니다.
org.json.JSONException : org.json.JSONArray 유형은 JSONObject로 변환 할 수 없습니다.
이것은 내 JSON 형식입니다.
[{ "id": "1", "nome": "admin", "email": "[email protected]", "password": "xxxxxxx"}]
언급 한 JSON 문자열은 "["로 시작하고 "]"로 끝납니다. 그것은 배열을 나타냅니다. JSON 개체는 "{"로 시작하고 "}"로 끝납니다.
JSON 문자열을 둘러싼 대괄호를 제거해야합니다. 그것은 당신의 문제를 해결할 것입니다.
가능하지 않은 경우 문자열에서 JSONArray를 만든 다음 첫 번째 항목을 사용하여 이름 및 이메일과 같은 속성을 가져올 수 있습니다.
JSONArray jsonArray = new JSONArray(response);
JSONObject obj = jsonArray.getJSONObject(0);
이렇게하면 문제가 해결됩니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다