0

Hi All I'm calling one php script from my Android code to insert record into the database. On successful insert I'm getting one string in following format-

{"success":1,"message":"Member registered successfully."}

And in case of error I'm getting the following string-

{"success":0,"message":"Oops! An error occurred."}

Now I wants to parse that string to check whether record is inserted successfully or not for that I have tried following code

JSONArray jsonarray = new JSONArray(response);
JSONObject jsonobj = jsonarray.getJSONObject(0);
String strResp=jsonobj.getString("success");

but strResp is getting null..! Please help. Thank you..!

3 Answers 3

1

The code.

JSONObject jObj = new JSONObject(response);
String strResp = jObj.getString("success");
Sign up to request clarification or add additional context in comments.

Comments

0

Try this

JSONObject jObj = new JSONObject(response);
String strResp = String.valueOf(jObj.getInt("success"));

Because success in your json response is int.

Comments

0
{ } means json object...and [  ] means json array..

here, {"success":1,"message":"Member registered successfully."} is json object...

so,

JSONObject jsonobj = jsonarray.getJSONObject(response);
String  strResp=jsonobj.getString("success");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.