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 3497512
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:22:46+00:00 2026-05-18T12:22:46+00:00

Hello Im trying to get the value of an element from a JsonObject. i’m

  • 0

Hello Im trying to get the value of an element from a JsonObject. i’m using java with the
Gson library.

here is the related part of the code:

String s = "http://maps.googleapis.com/maps/api/directions/json?origin=30.065634,31.209473&destination=29.984177,31.440052&sensor=false";
URL url = new URL(s);

BufferedReader r = new BufferedReader(new InputStreamReader(
    ((HttpURLConnection) url.openConnection()).getInputStream()));

JsonStreamParser jsp = new JsonStreamParser(r);

JsonParser jp = new JsonParser();

JsonElement jsonElement =  jp.parse(r);

JsonObject jsonObject = jsonElement.getAsJsonObject();

System.out.println(jsonObject.get("summary"));

here is a part of the Json:

"status": "OK",   "routes": [ {
    "summary": "Mehwar Al Moneeb",
    "legs": [ {
      "steps": [ {
        "travel_mode": "DRIVING",
        "start_location": {
          "lat": 30.0655100,
          "lng": 31.2096600
        },
        "end_location": {
          "lat": 30.0654400,
          "lng": 31.2096000
        },
        "polyline": {
          "points": "mdovDksn}DLJ",
          "levels": "BB"
        },
        "duration": {
          "value": 1,
          "text": "1 min"
        },
        "html_instructions": "Head \u003cb\u003esouthwest\u003c/b\u003e on \u003cb\u003eOmar Toson\u003c/b\u003e toward \u003cb\u003eMohammed Roshdi\u003c/b\u003e",
        "distance": {
          "value": 9,
          "text": "9 m"
        }
      }

When I get the top element “routes” its fine and printing it displays what inside the element but when I try to for example to get the element “summary” as shown, the return is null, thats whats is displayed in the output, so subsequently I cannot get the value of it.
Whats wrong? how can get the value of any JsonElement? Please reply back to me as soon as you can. Thanks in advance.

  • 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-05-18T12:22:47+00:00Added an answer on May 18, 2026 at 12:22 pm

    Routes is a javascript array. Summary is a property of the first object in that array, so you need to use jsonObject.getAsJsonArray("routes").get(0).get("summary"); or equivalent. I haven’t worked with your Java library, but the JS code would be jsonObject.routes[0].summary

    Edit: Looked up GSON Documentation and updated code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I am trying to get the options from a html select element. The
hello i'm trying to get the first value of a datagrid cell value but
I am trying to log from my C# Custom Action using session.Log( Hello World!
I'm trying to read input from the terminal. For this, I'm using a BufferedReader.
i have a label in my form, and im trying to get the value
Edit: Updating post based on Martins comments below Hello, I'm just trying to get
I'm trying something like this Output.py print Hello Input.py greeting = raw_input(Give me the
So I'm trying to run my first hello world prog written in C. I
py2exe does not work with the standard email module Hello. I am trying to
To be specific, I was trying this code: package hello; public class Hello {

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.