Hi, Friends.
I'm trying to solve the problem is my code or Json.
I'm using HttpClient to get Json
See Valid Json.
The result is this:
I'm not able to read the object. Could someone lend a hand and show what I am doing wrong?
Result Log
How can I map?
Tank You
I'm trying to solve the problem is my code or Json.
I'm using HttpClient to get Json
See Valid Json.
B4X:
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim URL As String
'URL = "http://192.168.100.5:8080/ServerFunctionInvoker"
URL="http://192.168.1.103:8080/datasnap/rest/TServicoVenda/getCliente(1)"
Dim HttpClient1 As HttpClient
'Dim sJSONData As String
End Sub
Sub Globals
Dim sJSONData As String
Dim Load As Button
Dim Parse As Button
Dim ListView1 As ListView
End Sub
Sub Activity_Create(FirstTime As Boolean)
HttpClient1.Initialize("HttpClient1")
Activity.LoadLayout("json1") 'Load the layout file.
End Sub
Sub HttpClient1_ResponseSuccess (Response As HttpResponse, TaskId As Int)
Log("ResponseSuccess")
ProgressDialogHide
Dim result As String
result = Response.GetString("UTF8") 'Convert the response to a string
sJSONData = result
Log(result) ' test dump
End Sub
Sub HttpClient1_ResponseError (Reason As String, StatusCode As Int, TaskId As Int)
Log(Reason)
Log(StatusCode)
ProgressDialogHide
msg = "Error connecting to server."
If Reason <> Null Then msg = msg & CRLF & Reason
ToastMessageShow (msg, True)
End Sub
Sub GetJSONData()
Dim request As HttpRequest
request.InitializeGet(URL)
request.Timeout = 10000 'set timeout to 10 seconds
If HttpClient1.Execute(request, 1) = False Then Return 'Will be false if their is already a running task (with the same id).
ProgressDialogShow("Calling server...")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Parse_Click
LoadJSONDATA
End Sub
Sub Load_Click
GetJSONData
End Sub
The result is this:
B4X:
{"result":[{"id":1,"nome":"Jonh Carter","cpf":"123.567.789.09"}]}
I'm not able to read the object. Could someone lend a hand and show what I am doing wrong?
B4X:
Sub LoadJSONDATA()
Log("Data:"&sJSONData)
Dim JSON As JSONParser
Dim Map1 As Map
JSON.Initialize(sJSONData)
Map1 = JSON.nextobject
Log(sJSONData)
Log(JSON)
Log(Map1)
End Sub
B4X:
ResponseSuccess
{"result":[{"id":1,"nome":"Jederson Zuchi","cpf":"123.456.789-10"}]}
Data:{"result":[{"id":1,"nome":"Jederson Zuchi","cpf":"123.456.789-10"}]}
{"result":[{"id":1,"nome":"Jederson Zuchi","cpf":"123.456.789-10"}]}
(JSONTokener) at character 68 of {"result":[{"id":1,"nome":"Jederson Zuchi","cpf":"123.456.789-10"}]}
(MyMap) {result=[{id=1, cpf=123.456.789-10, nome=Jederson Zuchi}]}
ResponseSuccess
{"result":[{"id":1,"nome":"Jonh Carter","cpf":"123.567.789.09"}]}
How can I map?
Tank You
Last edited: