I am having some problems pulling values from a JSON object. Here is my code
try {
JSONObject json = new JSONObject(result);
JSONObject json2 = json.getJSONObject("results");
test = json2.getString("name");
} catch (JSONException e) {
e.printStackTrace();
}
test
is declared as a String
. When the code runs it is showing null
. If I hover over json2
in debug mode I can see all the values and names within the object.
I also tried
test = json2.length();
This returned test = 0
. Even when I hover over the json2
object I can read the values within the object.
Here is an example of a JSON string I will use.
{
"caller":"getPoiById",
"results":
{
"indexForPhone":0,
"indexForEmail":"NULL",
"indexForHomePage":"NULL",
"indexForComment":"NULL",
"phone":"05137-930 68",
"cleanPhone":"0513793068",
"internetAccess":"2",
"overnightStay":"2",
"wasteDisposal":"2",
"toilet":"2",
"electricity":"2",
"cran":"2",
"slipway":"2",
"camping":"2",
"freshWater":"2",
"fieldNamesWithValue":["phone"],
"fieldNameTranslations": ["Telefon"],
"id":"1470",
"name":"Marina Rasche Werft GmbH & Co. KG",
"latitude":"52.3956107286487",
"longitude":"9.56583023071289"
}
}