Souraj Mandal Souraj Mandal - 1 year ago 140
JSON Question

Retrieve data from JSON object uing Graph API in Android Studio

I want to just get the email of the user of my application. I have used Graph API.

But I am facing problems in converting the received JSON object to a string and then retrieving the data from it.

Here is a part of my code:

new GraphRequest.GraphJSONObjectCallback() {
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
Log.v("LoginActivity", response.toString());
Bundle parameters = new Bundle();
parameters.putString("fields", "email");

How to get the email from the object?

Answer Source

Well in general just parse the JSON object like this

JSONObject jobj = new JSONObject(response.getRawResponse());
JSONArray data = jobj.getJSONArray("data");                             
for (int i = 0; i < data.length(); i++) {
     JSONObject indi = data.getJSONObject(i).getString("email");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download