Get Data From Json And Org.json.jsonexception Is Thrown
Solution 1:
From what you mentioned, it appears that you are doing this via an emulator.
Emulator may not be able to access http://localhost//
. You can try access using, loopback address or the ip address.
Solution 2:
You never verify that you actually have received anything after reading from the stream returned from the HttpEntity
. That exception is telling you there's no input at character 0 (The first character) - you have nothing to parse; it's an empty string. Nothing was ever appended to your StringBuilder
.
publicstaticvoidmain(String[] args) throws JSONException
{
String json = "{\"username\":\"not found\",\"password\":null}";
JSONObject jObj = newJSONObject(json);
}
Throws no such exception. Often writing a small test case will point you in the right direction.
As others have mentioned, this is probably because you are using the wrong URL or maybe your parameters? Since you're getting back a 200 OK
you're obviously connecting to a webserver and getting a response ... I'd check to see if that PHP is working as you expect.
Solution 3:
Inside simpleJarsonParser class, I replace the following code
HttpClienthttpClient=newDefaultHttpClient();
to
DefaultHttpClienthttpClient=newDefaultHttpClient();
and it works. And of course I have replace localhost to 10.0.2.2 as I'm using xampp and android emulator.
Post a Comment for "Get Data From Json And Org.json.jsonexception Is Thrown"