1

The JSONObject looks like

{"result":
     {
        "id":"1",
        "name":"ankur",
        "email":"[email protected]",
        "address":"bblock",
        "designation":"devloper",
        "department":"development",
        "balanceleave":"5"
     }
}

and my parse code looks like

Intent intent = new Intent(Login.this, Profile.class);
intent.putExtra("id", response.getString("id"));
intent.putExtra("name", response.getString("name"));
intent.putExtra("email", response.getString("email"));
intent.putExtra("address", response.getString("address"));
intent.putExtra("designation", response.getString("designation"));
intent.putExtra("department", response.getString("department"));
intent.putExtra("balanceleave", response.getString("balanceleave"));

startActivity(intent);

Can you help me out, actually I am parsing the JSON and sending it to the profile activity to display and if you can comeup with something that I can send the JSONObject to profile that would be great!!

1
  • What's the exact problem? You'll need to parse it somewhere right? Recommendation: Use Gson Commented Jul 8, 2017 at 8:02

3 Answers 3

2

Try like this :

JSONObject response=new JSONObject("your response string");
JSONObject result=response.getJSONObject("result");
String id=result.getString("id");
String name=result.getString("name"));
String email=result.getString("email"));
String address=result..getString("address"));
String designation=result.getString("designation"));
String department=result.getString("department"));
String balanceleave=result.getString("balanceleave"));
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks bro you answered my second upcoming question.
Welcome @YashKumarAtri
0

yes you have to convert JsonObject to String and then send via Bundle to Profile Screen. Like below

Intent intent = new Intent(Login.this, Profile.class);
intent.putExtra("JSON_OBJECT", response.toString());


                                startActivity(intent);

To Get that

Intent i = getIntent();
String json = i.getStringExtra("JSON_OBJECT");
try{
JsonObject json = new JsonObject(json);
}catch(Exception e){
}

Comments

0

You can write below line

JSONString url = objectname.getJsonString("url");

then put in intent

1 Comment

There is no url in the question

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.