简体   繁体   English

从java中的jsonArray获取数据

[英]fetching data from jsonArray in java

I have a JSON Array JsonArray.toString(0) whose value is:我有一个 JSON 数组JsonArray.toString(0)其值为:

{
  "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. IE。 "html_instructions". “html_指令”。

You need to first get JSON object of 0th index then only you can find that element.您需要先获取第 0 个索引的 JSON 对象,然后才能找到该元素。

Try this:尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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