-2
:これは
応答
{
"Response": {
"status": {
"type": "Success",
"message": "You are authorized to access"
},
"data": {
"msg": "Data Found",
"user": {
"user_id": "1",
"user_full_name": "User",
"user_name": "Username"
}
}
}
}
エラーサーバーから行われています?:
org.json.JSONException: Value {"Response":{"status":{"type":"Success","message":"You are authorized to access"},"data":{"msg":"Data Found","user":{"user_id":"1","user_full_name":"User","user_name":"username"}}}} of type org.json.JSONObject cannot be converted to JSONArray
コード:
String resp = response.body().string();
JSONArray arr = null;
try {
arr = new JSONArray(resp);
} catch (JSONException e) {
e.printStackTrace();
}
JSONObject jObj = null;
try {
jObj = arr.getJSONObject(0);
} catch (JSONException e) {
e.printStackTrace();
}
try {
String type = jObj.getString("type");
String msg = jObj.getString("message");
if(type == "Success"){
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}else{
Toast.makeText(getApplicationContext(),msg,Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
を私はこのJSONからマッサージ&のステータスを取得します。誰か助けてください。