0
{
"response": [
{
  "address": {
    "features": {
        ..........
    },
    "loc": {
      "latitude": 27.32423423423,
      "longitude": -84.0342423429
    },
    "blah1": "blah",
    "blah2": "blah",
    "stuff": {
      "stuff2": "stuff",
      "stuff3": "stuff"
    },
    "data": {
      .....
      },
      "interesting": {
        ...
      }
    },
    "l": null,
    "u": null
  },
  "a": null,
  "b": 0,
  "c": {
    ....
  },
  "d": "test",
  "type": null,
  "id": 53,
  "metadata": {
    ....
  },
  "asset": {
    "pack": [
      {
      ....
      }
    ]
  },
  "k": null,
  "z": null,
  "f": null
}
]}

Is there a way to get values from keys: "latitude" and "longitude" from "loc" and store them in global variables (in java) in a quick and efficient matter without having to loop through the JSONArray?

When I try loop through the JSON array, the variables that would hold the values for those keys would not be accessible outside the loop.

kastsabug
  • 37
  • 6

1 Answers1

0

Maybe you could try something like JsonPath. But I've no experience with it.

Have a look at this SO-Question.

morecore
  • 900
  • 3
  • 14
  • 32
  • nice answer and good read! I did read into it, but decided that instead of the import, I went about it the old fashion way, make the JSONArray into an object, transverse it, then put it back into a string, then back to an object and then back to an array until I got the key I wanted and stored it into a String. It was a bit messy at first, but it really does give you full control over the structure! Cheers! – kastsabug Jun 01 '17 at 18:36