Android Question How do i get the data from this string?

Rookie

Member
Licensed User
Longtime User
(MyMap) {ResponseMessage=[{"BookingItemID":1005,"ActionDate":"\/Date(1533111232000)\/","FleetNo":"216","driverid":4595,"BookingDate":"\/Date(1530002186990)\/","BookingRef":"","ClientRef":"PLS2","AllocateDate":"\/Date(1533111232000)\/","PlacementAddress":"PREMIER LOGISTICS SOLUTIONS, MEYERTON, JOHANNESBURG","DeliveryAddress":"PREMIER LOGISTICS SOLUTIONS, MEYERTON, JOHANNESBURG","PlannedDeliveryDate":null,"StatusWeight":300,"CompanyNo":"PW399","route":"DBN-JHB"}], ResponseResult=Success}
 

DonManfred

Expert
Licensed User
Longtime User
You are not providing enough informations. Where does this "string" come from?

It is not a String. It is a Map.

I guess you have others issues here too. I don´t think that you get the date values right.

Start with learning to work with Maps.

 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Using Erel's online tool: http://basic4ppc.com:51042/json/index.html
If you try to parse the below json string:
[{"BookingItemID":1005,"ActionDate":"\/Date(1533111232000)\/","FleetNo":"216","driverid":4595,"BookingDate":"\/Date(1530002186990)\/","BookingRef":"","ClientRef":"PLS2","AllocateDate":"\/Date(1533111232000)\/","PlacementAddress":"PREMIER LOGISTICS SOLUTIONS, MEYERTON, JOHANNESBURG","DeliveryAddress":"PREMIER LOGISTICS SOLUTIONS, MEYERTON, JOHANNESBURG","PlannedDeliveryDate":null,"StatusWeight":300,"CompanyNo":"PW399","route":"DBN-JHB"}]
You will end up with the data as follows:
B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As List = parser.NextArray
For Each colroot As Map In root
 Dim BookingDate As String = colroot.Get("BookingDate")
 Dim CompanyNo As String = colroot.Get("CompanyNo")
 Dim PlacementAddress As String = colroot.Get("PlacementAddress")
 Dim BookingItemID As Int = colroot.Get("BookingItemID")
 Dim DeliveryAddress As String = colroot.Get("DeliveryAddress")
 Dim ActionDate As String = colroot.Get("ActionDate")
 Dim FleetNo As String = colroot.Get("FleetNo")
 Dim PlannedDeliveryDate As String = colroot.Get("PlannedDeliveryDate")
 Dim route As String = colroot.Get("route")
 Dim driverid As Int = colroot.Get("driverid")
 Dim StatusWeight As Int = colroot.Get("StatusWeight")
 Dim BookingRef As String = colroot.Get("BookingRef")
 Dim ClientRef As String = colroot.Get("ClientRef")
 Dim AllocateDate As String = colroot.Get("AllocateDate")
Next
 
Upvote 0

Rookie

Member
Licensed User
Longtime User
i used the tool and it worked, copied the code but get an error with :

parser.Initialize(<text>)

text is undeclared,
 
Upvote 0

udg

Expert
Licensed User
Longtime User
You have to substitute <text> with whatever contains the data you posted.
 
Upvote 0

Rookie

Member
Licensed User
Longtime User
replaced text with j.getstring

Sub JobDone(j As HttpJob)

Log(j.Success)
If j.Success Then
Log(j.GetString)
'Dim parser As JSONParser
'parser.Initialize(j.GetString)
'Log(parser.NextObject)



Dim parser As JSONParser
parser.Initialize(j.GetString)
Dim root As Map = parser.NextObject
root.Initialize
Dim json As Map = root.Get("json")
json.Initialize
Dim ResponseResult As String = json.Get("ResponseResult")
Dim ResponseMessage As List = json.Get("ResponseMessage")
ResponseMessage.Initialize
For Each colResponseMessage As Map In ResponseMessage
Dim BookingDate As String = colResponseMessage.Get("BookingDate")
Dim CompanyNo As String = colResponseMessage.Get("CompanyNo")
Dim PlacementAddress As String = colResponseMessage.Get("PlacementAddress")
Dim BookingItemID As Int = colResponseMessage.Get("BookingItemID")
Dim DeliveryAddress As String = colResponseMessage.Get("DeliveryAddress")
Dim ActionDate As String = colResponseMessage.Get("ActionDate")
Dim FleetNo As String = colResponseMessage.Get("FleetNo")
Dim PlannedDeliveryDate As String = colResponseMessage.Get("PlannedDeliveryDate")
Dim route As String = colResponseMessage.Get("route")
Dim driverid As Int = colResponseMessage.Get("driverid")
Dim StatusWeight As Int = colResponseMessage.Get("StatusWeight")
Dim BookingRef As String = colResponseMessage.Get("BookingRef")
Dim ClientRef As String = colResponseMessage.Get("ClientRef")
Dim AllocateDate As String = colResponseMessage.Get("AllocateDate")


Log(ResponseMessage)
Log( ResponseResult)
Next
Log(j.ErrorMessage)
End If
j.Release

End Sub
 
Upvote 0

Rookie

Member
Licensed User
Longtime User
this is the log

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
true
{"ResponseMessage":"[{\"BookingItemID\":1005,\"ActionDate\":\"\\\/Date(1533111232000)\\\/\",\"FleetNo\":\"216\",\"driverid\":4595,\"BookingDate\":\"\\\/Date(1530002186990)\\\/\",\"BookingRef\":\"\",\"ClientRef\":\"PLS2\",\"AllocateDate\":\"\\\/Date(1533111232000)\\\/\",\"PlacementAddress\":\"PREMIER LOGISTICS SOLUTIONS, MEYERTON, JOHANNESBURG\",\"DeliveryAddress\":\"PREMIER LOGISTICS SOLUTIONS, MEYERTON, JOHANNESBURG\",\"PlannedDeliveryDate\":null,\"StatusWeight\":300,\"CompanyNo\":\"PW399\",\"route\":\"DBN-JHB\"}]","ResponseResult":"Success"}
 
Upvote 0

Rookie

Member
Licensed User
Longtime User
the tool returned these values with the same input

json
  • ResponseResult: Success
  • ResponseMessage
    • 0
      • BookingDate: /Date(1530002186990)/
      • CompanyNo: PW399
      • PlacementAddress: PREMIER LOGISTICS SOLUTIONS, MEYERTON, JOHANNESBURG
      • BookingItemID: 1005
      • DeliveryAddress: PREMIER LOGISTICS SOLUTIONS, MEYERTON, JOHANNESBURG
      • ActionDate: /Date(1533111232000)/
      • FleetNo: 216
      • PlannedDeliveryDate: null
      • route: DBN-JHB
      • driverid: 4595
      • StatusWeight: 300
      • BookingRef:
      • ClientRef: PLS2
      • AllocateDate: /Date(1533111232000)/
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Reading from post #7 (i.e. copying and pasting from post to on-line tool)
It seems to me that the input string is not a properly formatted JSON string, but I could be wrong.
"ResponseMessage":" <-- this last char makes ResponseMessage value a string not a list.

After pasting that string, the tool suggests (correctly), the following:
B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As Map = parser.NextObject
Dim ResponseResult As String = root.Get("ResponseResult")
Dim ResponseMessage As String = root.Get("ResponseMessage")

why dont the log show any result for ResponseMessage ?
Because your code works on an empty string..look at root.Initialize and json.initialize in it.
B4X:
Dim root As Map = parser.NextObject
root.Initialize
Here you first assign a vale to root then empty it again initialing it.
 
Last edited:
Upvote 0
Top