Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9200285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:43:55+00:00 2026-06-17T22:43:55+00:00

I am trying to parse JSON to get few fields from it. Below is

  • 0

I am trying to parse JSON to get few fields from it. Below is my JSON-

{
   "id": "100000224942080000",
   "name": "Tech Geeky",
   "first_name": "Tech",
   "last_name": "Geeky",
   "link": "https://www.facebook.com/tech.geeky",
   "username": "tech.geeky",
   "work": [
      {
         "employer": {
            "id": "1854993931353456",
            "name": "Tech"
         },
         "location": {
            "id": "1119482345542155151",
            "name": "Santa Cruz, California"
         },
         "position": {
            "id": "280794135283124256",
            "name": "Senior"
         },
         "start_date": "2012-01"
      }
   ],
   "education": [
      {
         "school": {
            "id": "131182196916370",
            "name": "Fatima School, Gonda"
         },
         "year": {
            "id": "113125125403208",
            "name": "2004"
         },
         "type": "High School"
      }
   ],
   "gender": "male"
}

I need to extract id, name, first_name, last_name, gender from the above JSON. Below is my program that I wrote but it throws exception somehow. What wrong I am doing in that?

public class JSONParser {

    private static final String URL = "https://graph.facebook.com/me?access_token=AAAG2HjMOAsEBAGBhjx2RqqLbOvnAZAxEPQ0X7ZC2JWY0YcQZDZDSSSAFTR";
    private static HashMap<String, String> output = null;

    public static void main(String[] args) throws Exception {

    StringBuilder builder = new StringBuilder();
    DefaultHttpClient httpclient = new DefaultHttpClient();
    output = new HashMap<String, String>();
    BufferedReader bufferedReader = null;
    try {
        HttpGet httpget = new HttpGet(URL);
        httpget.getRequestLine();
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        //System.out.println(response.getStatusLine());
        if (entity != null) {
        InputStream inputStream = entity.getContent();
        bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        for (String line = null; (line = bufferedReader.readLine()) != null;) {
            builder.append(line).append("\n");
        }
        JSONObject jsonObject = new JSONObject(builder.toString());
        JSONObject info = jsonObject.getJSONObject("id");
        parseJSONObject(info, output);
        }
    } catch (Exception e) {

    } finally {
        try {
        bufferedReader.close();
        httpclient.getConnectionManager().shutdown();
        } catch (IOException e) {

        }
    }
    }

    private static HashMap<String, String> parseJSONObject(JSONObject json,
        HashMap<String, String> output) throws JSONException {

    Iterator<String> keys = json.keys();
    while (keys.hasNext()) {
        String key = keys.next();
        String val = null;
        try {
        JSONObject value = json.getJSONObject(key);
        parseJSONObject(value, output);
        } catch (Exception e) {
        val = json.getString(key);
        }
        if (val != null) {
        output.put(key, val);
        }
    }
    return output;
    }

}

Exception:-

org.json.JSONException: JSONObject["id"] is not a JSONObject.

NOTE:-
JSON is correct. I have slightly modified JSON before posting it here. So it might be possible something gone wrong in copying pasting here. But assuming JSON is right.. Still it throws an exception.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:43:56+00:00Added an answer on June 17, 2026 at 10:43 pm

    You could get the fields by getting their data type values like this:

    int id = jsonObject.getInt("id");
    String name = jsonObject.getString("name");
    String firstName = jsonObject.getString("first_name");
    String lastName = jsonObject.getString("last_name");
    String gender = jsonObject.getString("gender");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to parse a JSON string from USGS . However I get
I am trying to parse this json data from the url but i get
I am trying to parse the JSON response get from the server and I
I'm trying to parse JSON with jQuery I get from a remote server through
I am trying to parse a JSON script from my server which contains a
I am trying to parse the json values from the following stream: {id: tag:search.xxxxx.com,2005:xxxxxxxxxxx}
I;m trying to parse a json string which I receive from web server as
I am trying to parse the following JSON string remotely: [{name:Object1,data:[1,2]},{name:Object2,data:[3,4]}] I am doing
I'm trying to load and parse json data from an external source into a
I'm trying to parse a JSON string but when I do I get undefined.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.