Android Question [SOLVED] Newbie JSON


Well-Known Member
Licensed User
Longtime User

I try to learn how the JSON works but I can't pass over this point.
So I use a simple API from to retrieve geolocation

The JSON Look like
{"ip":"","continent_code":"NA","continent_name":"North America","country_code2":"US",
"country_code3":"USA","country_name":"United States","country_capital":"Washington, D.C.","state_prov":"Louisiana",
"geoname_id":"4343811","isp":"Level 3 Parent, LLC","connection_type":"","organization":"Level 3 Parent, LLC",
"currency":{"code":"USD","name":"US Dollar","symbol":"$"},
"time_zone":{"name":"America/Chicago","offset":-6,"current_time":"2022-03-07 05:38:42.207-0600","current_time_unix":1646653122.207,"is_dst":false,"dst_savings":1}}

And my code is

Dim parser As JSONParser
    Dim TheRoot As Map = parser.NextObject
    Dim continent_name As String = TheRoot.Get("continent_name")
    Dim country_tld As String = TheRoot.Get("country_tld")
    Dim calling_code As String = TheRoot.Get("calling_code")
    Dim languages As String = TheRoot.Get("languages")
    Dim connection_type As String = TheRoot.Get("connection_type")
    Dim city As String = TheRoot.Get("city")
    Dim ip As String = TheRoot.Get("ip")
    Dim latitude As String = TheRoot.Get("latitude")
    Dim isp As String = TheRoot.Get("isp")
    Dim continent_code As String = TheRoot.Get("continent_code")
    Dim time_zone As Map = TheRoot.Get("time_zone")
    Dim offset As Int = time_zone.Get("offset")
    Dim dst_savings As Int = time_zone.Get("dst_savings")
    Dim thename As String = time_zone.Get("name")
    Dim current_time_unix As Double = time_zone.Get("current_time_unix")
    Dim current_time As String = time_zone.Get("current_time")
    Dim is_dst As String = time_zone.Get("is_dst")
    Dim geoname_id As String = TheRoot.Get("geoname_id")
    Dim zipcode As String = TheRoot.Get("zipcode")
    Dim district As String = TheRoot.Get("district")
    Dim organization As String = TheRoot.Get("organization")
    Dim country_code2 As String = TheRoot.Get("country_code2")
    Dim country_name As String = TheRoot.Get("country_name")
    Dim is_eu As String = TheRoot.Get("is_eu")
    Dim country_code3 As String = TheRoot.Get("country_code3")
    Dim state_prov As String = TheRoot.Get("state_prov")
    Dim currency As Map = TheRoot.Get("currency")
    Dim symbol As String = currency.Get("symbol")
    Dim code As String = currency.Get("code")
    Dim name As String = currency.Get("name")
    Dim country_capital As String = TheRoot.Get("country_capital")
    Dim country_flag As String = TheRoot.Get("country_flag")
    Dim longitude As String = TheRoot.Get("longitude")

When I execute my app I get the error like

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
Error occurred on line: 32 (B4XMainPage)
java.lang.RuntimeException: JSON Object expected.
    at anywheresoftware.b4a.objects.collections.JSONParser.NextObject(
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(
    at anywheresoftware.b4a.BA.raiseEvent(
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(
    at android.view.View.performClick(
    at android.view.View.performClickInternal(
    at android.view.View.access$3500(
    at android.view.View$
    at android.os.Handler.handleCallback(
    at android.os.Handler.dispatchMessage(
    at android.os.Looper.loop(
    at java.lang.reflect.Method.invoke(Native Method)
** Activity (main) Pause event (activity is not paused). **

Something is wrong with the map return from string?
I am wrong?
Last edited:


Licensed User
Longtime User
And my code is
Not when this error raises. Based on the error you where uing NextArray and not NextObject

BTW you can not use the jsonparser like this!

You first need to use okhttputils2 to download it, put the result into a string and give this string to the parser.
Upvote 1