Sub getipinfo(gip As String)
Dim j As HttpJob
Dim urllok As String
Dim getdata As String
urllok = "http://ip-api.com/php/"&gip
j.Initialize("", Me)
j.Download(urllok)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
getdata = j.GetString
End If
j.Release
' parse the out put of getdata
End Sub
i wanted to parse out this data like grabing country , region , etc.. which i couldn't do it sense the string is not static each time its change
Dim parsedip As String = ipdata'data from http job
Dim parser As JSONParser
parser.Initialize(parsedip)
Dim mparse As Map = parser.NextObject
Dim country As String = mparse.Get("country")
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As Map = parser.NextObject
Dim zip As String = root.Get("zip")
Dim country As String = root.Get("country")
Dim city As String = root.Get("city")
Dim org As String = root.Get("org")
Dim timezone As String = root.Get("timezone")
Dim isp As String = root.Get("isp")
Dim query As String = root.Get("query")
Dim regionName As String = root.Get("regionName")
Dim lon As Double = root.Get("lon")
Dim as As String = root.Get("as")
Dim countryCode As String = root.Get("countryCode")
Dim region As String = root.Get("region")
Dim lat As Double = root.Get("lat")
Dim status As String = root.Get("status")
1. You should always create a new thread for YOUR questions. Do not post to existing threads.
2. you are not providing enough infos. Additionally i do not understand the question. Be more detailed. What exactly are you trying to archieve?
Tanks Manfred!
in the present example I want to include the result obtained from the line: [Dim country As String = root.Get ("country")] in a label, how to do?
Very Thanks Manfred!
One last question from beginner,
would the final code look like this?
B4X:
Sub getipinfo(gip As String)
Dim j As HttpJob
Dim urllok As String
Dim getdata As String
urllok = "http://ip-api.com/php/"&gip
j.Initialize("", Me)
j.Download(urllok)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As Map = parser.NextObject
Dim zip As String = root.Get("zip")
Dim country As String = root.Get("country")
Dim city As String = root.Get("city")
Dim org As String = root.Get("org")
Dim timezone As String = root.Get("timezone")
Dim isp As String = root.Get("isp")
Dim query As String = root.Get("query")
Dim regionName As String = root.Get("regionName")
Dim lon As Double = root.Get("lon")
Dim as As String = root.Get("as")
Dim countryCode As String = root.Get("countryCode")
Dim region As String = root.Get("region")
Dim lat As Double = root.Get("lat")
Dim status As String = root.Get("status")
End If
j.Release
End sub
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private Button1 As Button
Private Label1 As Label
Private Label2 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("ipinfo")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ipinfo
Dim GetAddressJob As HttpJob
GetAddressJob.Initialize("GetAddress", Me)
GetAddressJob.Download("http://ip-api.com/json/")
Wait For (GetAddressJob) JobDone(GetAddressJob As HttpJob)
If GetAddressJob.Success Then
Dim parser As JSONParser
parser.Initialize(GetAddressJob.GetString)
Dim root As Map = parser.NextObject
Dim zip As String = root.Get("zip")
Dim country As String = root.Get("country")
Dim city As String = root.Get("city")
Dim lat As Double = root.Get("lat")
Dim lon As Double = root.Get("lon")
Log($"country: ${country}"$)
Log($"city: ${city}"$)
Log($"zip: ${zip}"$)
Log($"lat: ${lat}"$)
Log($"lon: ${lon}"$)
Label1.Text=country
Label2.Text=city
End If
GetAddressJob.Release
End Sub
Sub Button1_Click
ipinfo
End Sub