简体   繁体   中英

fetching data from jsonArray in java

I have a JSON Array JsonArray.toString(0) whose value is:

{
  "html_instructions": "Head <b>west</b> on <b>Park St</b> toward <b>Glenferrie Rd</b>/<b>State Route 19</b>",
  "duration": {
    "value": 40,
    "text": "1 min"
  },
  "distance": {
    "value": 109,
    "text": "0.1 km"
  },
  "end_location": {
    "lng": 145.0358882,
    "lat": -37.8197498
  },
  "polyline": {
    "points": "huyeF}pftZIjAC`@MdC"
  },
  "travel_mode": "DRIVING",
  "start_location": {
    "lng": 145.0371141,
    "lat": -37.8198945
  }
}

how can I extract only the first element from this? ie. "html_instructions".

You need to first get JSON object of 0th index then only you can find that element.

Try this:

jsonArray.getJSONObject(0).get("html_instruction")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM