Error:
W/System.err﹕ org.json.JSONException: Value [] of type org.json.JSONArray cannot be converted to JSONObject
W/System.err﹕ at org.json.JSON.typeMismatch(JSON.java:111)
W/System.err﹕ at org.json.JSONObject.<init>(JSONObject.java:158)
W/System.err﹕ at org.json.JSONObject.<init>(JSONObject.java:171)
Code :
Inside a try block
post.setEntity(new UrlEncodedFormEntity(data_to_send));
HttpResponse httpResponse = client.execute(post);
HttpEntity entity = httpResponse.getEntity();
String result = EntityUtils.toString(entity);
JSONObject jsonObject = new JSONObject(result);
if(jsonObject.length() == 0)
{
retunedContact = null;
}
else
{
String name,email;
name = null;
email=null;
if(jsonObject.has("name"))
name = jsonObject.getString("name");
if(jsonObject.has("email"))
email =jsonObject.getString("email");
retunedContact = new Contact(name , email , contact.username , contact.password);
}
catch(Exception e)
{
e.printStackTrace();
}