I have this string that gets passed from the server:
{\"error\":\"email_in_diff_account\"}
It is created in PHP like this:
$post_data = array('error' => "email_in_diff_account");
echo json_encode($post_data);
But when I try to parse it like this in JAVA:
JSONArray obj = new JSONArray(result);
It causes the following exception.
org.json.JSONObject cannot be converted to JSONArray
Would anyone know how to fix this? Am I not creating the JSON correctly in php?
If you’re using http://www.json.org/javadoc/org/json/JSONArray.html
You are trying to parse an array but you are passing it an object, you should use http://www.json.org/javadoc/org/json/JSONObject.html