Android Question Prasing JSON Error

Hello!

I am having trouble in parsing this particular JSON code. Please let me know what, and where specifically is the problem. Below is my code


B4X:
Sub Class_Globals
    Public csrf As String
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    GetCSRF
End Sub

Sub GetCSRF
    Private job As HttpJob
    Private parts() As String
    Private gcsrf As String
    
    job.Initialize("job", Me)
    
    job.Download("xxxxx")
    
    job.GetRequest.SetHeader("Content-Type", "application/json")
    job.GetRequest.SetHeader("X-API-KEY", "X-API-KEY2")
    job.GetRequest.SetHeader("Authentication", "Basic Og==")
    
    Wait For (job) JobDone (job As HttpJob)
    If job.Success Then
        Private jp As JSONParser
            
        Private parts2() As String
        jp.Initialize(job.GetString)
        parts = Regex.Split(":", jp)
        parts2 = Regex.Split($"""$, parts(3))
        
        csrf = parts2(1)
    End If
    job.Release
End Sub

Sub adminLogin
    Private j As HttpJob
    Private parts() As String
    Private parts2() As String
    Private admin_csrf As String
    Private NV As Map
    
    j.Initialize("j", Me)
    
    Log(Main.Uname &" "& Main.Pword &" "& csrf)
    NV.Initialize
    NV.Put("txtUserName", Main.Uname)
    NV.Put("txtPassword", Main.Pword)
    NV.Put("csrf_token_nadej", csrf)
    j.PostMultipart("xxxxx", NV, Null)
    
    j.GetRequest.SetHeader("Content-Type", "application/json")
    j.GetRequest.SetHeader("X-API-KEY", "X-API-KEY2")
    j.GetRequest.SetHeader("Authentication", "Basic Og==")
    
    Wait For (j) JobDone (j As HttpJob)
    If j.Success Then
        Private jp As JSONParser
        Private map1 As Map
        Private Username As String
        Private AccountIndex As String
        Private StoreID As String
        Private Login_token As String
        
        Private m As Map
        
        jp.Initialize(j.GetString)
        
        map1 = jp.NextObject
        
        If map1.Get("status") <> False Then
            
            If map1.Get("result") <> Null Then
                Private jp2 As JSONParser
                
                jp2.Initialize(map1.Get("result"))
                
                m = jp2.NextObject
                
                csrf = m.Get("token")
            End If
            
            Username = map1.Get("UserName")
            AccountIndex = map1.Get("AccountIndex")
            StoreID = map1.Get("StoreID")
            Login_token = map1.Get("csrf_token_nadej")
            
            OrderforAcceptance(csrf, Login_token)
        End If

        
    Else
        MsgboxAsync("Incorrect username and password. Please enter correct login.", "Incorrect Login!")
    End If
    j.Release
End Sub

Sub OrderforAcceptance(main_csrf As String, admin_csrf As String)
    Private job As HttpJob
    Private gcsrf As String
    Private NV As Map
    
    Private RefNo As String
    Private CartTotal As Double
    Private CustomerName As String
    Private MobileNo As String
    Private Urgency As String
    Private DeliveryDateTime As String
    Private Logo As String
    Private Location As String
    Private StoreID As Int
    Private DeliverAddress As String
    Private SpecificAddress As String
    Private ReqChangeAmount As Double
    Private AssignmentAccepted As Int
    Private OrderID As String
    Private TransNo As String
    Private Status As String
    Private Pickup As Int
    Private Transpo As String
    Private StoreID As Int
    Private token As String
    
    job.Initialize("job", Me)
    
    NV.Initialize
    NV.Put("Token", main_csrf)
    NV.Put("csrf_token_nadej", admin_csrf)
    job.PostMultipart("xxxx", NV, Null)
    
    job.GetRequest.SetHeader("Content-Type", "application/json")
    job.GetRequest.SetHeader("X-API-KEY", "X-API-KEY2")
    job.GetRequest.SetHeader("Authentication", "Basic Og==")
    
    Wait For (job) JobDone (job As HttpJob)
    If job.Success Then
        Private jp As JSONParser
        Private map1 As Map
        Private jg As JSONGenerator
        
        jp.Initialize(job.GetString)
        
        map1 = jp.NextObject
        
        jg.Initialize(map1)
        
        Log(jg.ToPrettyString(2))
        
        If map1.Get("status") <> False Then
            
            If map1.Get("data") <> Null Then
                Private jp2 As JSONParser
                Private m As Map
                
                Log(map1.Get("data"))
                
                jp2.Initialize(map1.Get("data"))
                m = jp2.NextObject

                jg.Initialize(m)
                Log(jg.ToPrettyString(2))
'               
'                RefNo = m.Get("RefNo")
'                CartTotal = m.Get("CartTotal")
'                CustomerName = m.Get("CustomerName")
'                MobileNo = m.Get("MobileNo")
'                Urgency = m.Get("Urgency")
'                DeliveryDateTime = m.Get("DeliveryDateTime")
'                Logo = m.Get("Logo")
'                Location = m.Get("Location")
'                StoreID = m.Get("StoreID")
'                DeliverAddress = m.Get("DeliveryAddress")
'                SpecificAddress = m.Get("SpecificAddress")
'                ReqChangeAmount = m.Get("ReqChangeAmount")
'                AssignmentAccepted = m.Get("AssignmentAccepted")
'                OrderID = m.Get("OrderID")
'                TransNo = m.Get("TransNo")
'                Status = m.Get("Status")
'                Pickup = m.Get("Pickup")
'                Transpo = m.Get("Transpo")
'                StoreID = map1.Get("StoreID")
'                token = map1.Get("csrf_token_nadej")
                
            End If

        End If
'        Log(RefNo)
'        Log(CartTotal)
'        Log(MobileNo)
'        Log(Urgency)
'        Log(DeliveryDateTime)
'        Log(Logo)
'        Log(StoreID)
'        Log(DeliverAddress)
'        Log(SpecificAddress)
'        Log(ReqChangeAmount)
'        Log(AssignmentAccepted)
'        Log(OrderID)
'        Log(TransNo)
'        Log(Status)
'        Log(Pickup)
'        Log(Transpo)
'        Log(StoreID)
'        Log(token)
    Else
        MsgboxAsync("Current Order Error","Error")
    End If
    job.Release
End Sub

And here is the complete error detail:

Logger connected to: HUAWEI STK-L22
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
govesmart_shopper adm1n 4a78dad1d81cc4bb880e73f8642900ae
{
"status": true,
"data": [
{
"RefNo": "0253",
"CartTotal": "1000",
"CustomerName": "Kb Villar",
"MobileNo": "31949",
"Urgency": "Express",
"DeliveryDateTime": "2020-06-25 16:00:00",
"Logo": "211b4a71475a94e6aaec9cfa67a5354a.png",
"Location": "GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines",
"StoreID": "16",
"DeliveryAddress": "Wilson Street, Wilson St, Iloilo City Proper, Iloilo City, Iloilo, Philippines",
"SpecificAddress": "ksks",
"ReqChangeAmount": "0",
"AssignmentAccepted": "0",
"OrderID": "253",
"TransNo": "5EF444AB57F8A",
"Status": "S",
"Pickup": "0",
"Transpo": "M"
},
{
"RefNo": "0330",
"CartTotal": "900",
"CustomerName": "Herbert John Escullar",
"MobileNo": "09298259994",
"Urgency": "Scheduled",
"DeliveryDateTime": "2020-07-23 08:00:00",
"Logo": "211b4a71475a94e6aaec9cfa67a5354a.png",
"Location": "GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines",
"StoreID": "16",
"DeliveryAddress": "Pavia Plaza, Pavia Plaza, Pavia, Iloilo, Philippines",
"SpecificAddress": "test",
"ReqChangeAmount": "3",
"AssignmentAccepted": "0",
"OrderID": "330",
"TransNo": "5F1049A138847",
"Status": "S",
"Pickup": "0",
"Transpo": "M"
},
{
"RefNo": "0338",
"CartTotal": "500",
"CustomerName": "Jon Caesar Basco",
"MobileNo": "09553174861",
"Urgency": "Scheduled",
"DeliveryDateTime": "2020-07-22 10:00:00",
"Logo": "211b4a71475a94e6aaec9cfa67a5354a.png",
"Location": "GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines",
"StoreID": "16",
"DeliveryAddress": "Wilson Street, Wilson St, Iloilo City Proper, Iloilo City, Iloilo, Philippines",
"SpecificAddress": "test",
"ReqChangeAmount": "445",
"AssignmentAccepted": "0",
"OrderID": "338",
"TransNo": "5F16B18FE3B9A",
"Status": "S",
"Pickup": "0",
"Transpo": "M"
},
{
"RefNo": "0340",
"CartTotal": "3920",
"CustomerName": "Kb Villar",
"MobileNo": "31949",
"Urgency": "Scheduled",
"DeliveryDateTime": "2020-07-23 07:00:00",
"Logo": "211b4a71475a94e6aaec9cfa67a5354a.png",
"Location": "GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines",
"StoreID": "16",
"DeliveryAddress": "Wilson Street, Wilson St, Iloilo City Proper, Iloilo City, Iloilo, Philippines",
"SpecificAddress": "ksks",
"ReqChangeAmount": "6080",
"AssignmentAccepted": "0",
"OrderID": "340",
"TransNo": "5F17EDECEFA41",
"Status": "S",
"Pickup": "1",
"Transpo": "M"
},
{
"RefNo": "0345",
"CartTotal": "500",
"Custome
Message longer than Log limit (4000). Message was truncated.
[{RefNo=0253, CartTotal=1000, CustomerName=Kb Villar, MobileNo=31949, Urgency=Express, DeliveryDateTime=2020-06-25 16:00:00, Logo=211b4a71475a94e6aaec9cfa67a5354a.png, Location=GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines, StoreID=16, DeliveryAddress=Wilson Street, Wilson St, Iloilo City Proper, Iloilo City, Iloilo, Philippines, SpecificAddress=ksks, ReqChangeAmount=0, AssignmentAccepted=0, OrderID=253, TransNo=5EF444AB57F8A, Status=S, Pickup=0, Transpo=M}, {RefNo=0330, CartTotal=900, CustomerName=Herbert John Escullar, MobileNo=09298259994, Urgency=Scheduled, DeliveryDateTime=2020-07-23 08:00:00, Logo=211b4a71475a94e6aaec9cfa67a5354a.png, Location=GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines, StoreID=16, DeliveryAddress=Pavia Plaza, Pavia Plaza, Pavia, Iloilo, Philippines, SpecificAddress=test, ReqChangeAmount=3, AssignmentAccepted=0, OrderID=330, TransNo=5F1049A138847, Status=S, Pickup=0, Transpo=M}, {RefNo=0338, CartTotal=500, CustomerName=Jon Caesar Basco, MobileNo=09553174861, Urgency=Scheduled, DeliveryDateTime=2020-07-22 10:00:00, Logo=211b4a71475a94e6aaec9cfa67a5354a.png, Location=GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines, StoreID=16, DeliveryAddress=Wilson Street, Wilson St, Iloilo City Proper, Iloilo City, Iloilo, Philippines, SpecificAddress=test, ReqChangeAmount=445, AssignmentAccepted=0, OrderID=338, TransNo=5F16B18FE3B9A, Status=S, Pickup=0, Transpo=M}, {RefNo=0340, CartTotal=3920, CustomerName=Kb Villar, MobileNo=31949, Urgency=Scheduled, DeliveryDateTime=2020-07-23 07:00:00, Logo=211b4a71475a94e6aaec9cfa67a5354a.png, Location=GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines, StoreID=16, DeliveryAddress=Wilson Street, Wilson St, Iloilo City Proper, Iloilo City, Iloilo, Philippines, SpecificAddress=ksks, ReqChangeAmount=6080, AssignmentAccepted=0, OrderID=340, TransNo=5F17EDECEFA41, Status=S, Pickup=1, Transpo=M}, {RefNo=0345, CartTotal=500, CustomerName=Jon Caesar Basco, MobileNo=09553174861, Urgency=Express, DeliveryDateTime=2020-07-25 18:00:00, Logo=211b4a71475a94e6aaec9cfa67a5354a.png, Location=GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines, StoreID=16, DeliveryAddress=Wilson Street, Wilson St, Iloilo City Proper, Iloilo City, Iloilo, Philippines, SpecificAddress=test, ReqChangeAmount=63, AssignmentAccepted=0, OrderID=345, TransNo=5F1BF3DC32C11, Status=S, Pickup=0, Transpo=M}]
Error occurred on line: 159 (API)
org.json.JSONException: Unterminated object at character 47 of [{RefNo=0253, CartTotal=1000, CustomerName=Kb Villar, MobileNo=31949, Urgency=Express, DeliveryDateTime=2020-06-25 16:00:00, Logo=211b4a71475a94e6aaec9cfa67a5354a.png, Location=GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines, StoreID=16, DeliveryAddress=Wilson Street, Wilson St, Iloilo City Proper, Iloilo City, Iloilo, Philippines, SpecificAddress=ksks, ReqChangeAmount=0, AssignmentAccepted=0, OrderID=253, TransNo=5EF444AB57F8A, Status=S, Pickup=0, Transpo=M}, {RefNo=0330, CartTotal=900, CustomerName=Herbert John Escullar, MobileNo=09298259994, Urgency=Scheduled, DeliveryDateTime=2020-07-23 08:00:00, Logo=211b4a71475a94e6aaec9cfa67a5354a.png, Location=GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines, StoreID=16, DeliveryAddress=Pavia Plaza, Pavia Plaza, Pavia, Iloilo, Philippines, SpecificAddress=test, ReqChangeAmount=3, AssignmentAccepted=0, OrderID=330, TransNo=5F1049A138847, Status=S, Pickup=0, Transpo=M}, {RefNo=0338, CartTotal=500, CustomerName=Jon Caesar Basco, MobileNo=09553174861, Urgency=Scheduled, DeliveryDateTime=2020-07-22 10:00:00, Logo=211b4a71475a94e6aaec9cfa67a5354a.png, Location=GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines, StoreID=16, DeliveryAddress=Wilson Street, Wilson St, Iloilo City Proper, Iloilo City, Iloilo, Philippines, SpecificAddress=test, ReqChangeAmount=445, AssignmentAccepted=0, OrderID=338, TransNo=5F16B18FE3B9A, Status=S, Pickup=0, Transpo=M}, {RefNo=0340, CartTotal=3920, CustomerName=Kb Villar, MobileNo=31949, Urgency=Scheduled, DeliveryDateTime=2020-07-23 07:00:00, Logo=211b4a71475a94e6aaec9cfa67a5354a.png, Location=GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines, StoreID=16, DeliveryAddress=Wilson Street, Wilson St, Iloilo City Proper, Iloilo City, Iloilo, Philippines, SpecificAddress=ksks, ReqChangeAmount=6080, AssignmentAccepted=0, OrderID=340, TransNo=5F17EDECEFA41, Status=S, Pickup=1, Transpo=M}, {RefNo=0345, CartTotal=500, CustomerName=Jon Caesar Basco, MobileNo=09553174861, Urgency=Express, DeliveryDateTime=2020-07-25 18:00:00, Logo=211b4a71475a94e6aaec9cfa67a5354a.png, Location=GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines, StoreID=16, DeliveryAddress=Wilson Street, Wilson St, Iloilo City Proper, Iloilo City, Iloilo, Philippines, SpecificAddress=test, ReqChangeAmount=63, AssignmentAccepted=0, OrderID=345, TransNo=5F1BF3DC32C11, Status=S, Pickup=0, Transpo=M}]
at org.json.JSONTokener.syntaxError(JSONTokener.java:460)
at org.json.JSONTokener.readObject(JSONTokener.java:403)
at org.json.JSONTokener.nextValue(JSONTokener.java:104)
at org.json.JSONTokener.readArray(JSONTokener.java:440)
at org.json.JSONTokener.nextValue(JSONTokener.java:107)
at anywheresoftware.b4a.objects.collections.JSONParser.NextObject(JSONParser.java:48)
at Nadej.Shopper.api$ResumableSub_OrderforAcceptance.resume(api.java:648)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA$2.run(BA.java:387)
at android.os.Handler.handleCallback(Handler.java:888)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lan
Message longer than Log limit (4000). Message was truncated.


Thank you in advance for your assistance!
 

DonManfred

Expert
Licensed User
Longtime User
[{RefNo=0253, CartTotal=1000, CustomerName=Kb Villar, MobileNo=31949, Urgency=Express, DeliveryDateTime=2020-06-25 16:00:00, Logo=211b4a71475a94e6aaec9cfa67a5354a.png, Location=GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines, StoreID=16, DeliveryAddress=Wilson Street, Wilson St, Iloilo City Proper, Iloilo City, Iloilo, Philippines, SpecificAddress=ksks, ReqChangeAmount=0, AssignmentAccepted=0, OrderID=253, TransNo=5EF444AB57F8A, Status=S, Pickup=0, Transpo=M}, {RefNo=0330, CartTotal=900, CustomerName=Herbert John Escullar, MobileNo=09298259994, Urgency=Scheduled, DeliveryDateTime=2020-07-23 08:00:00, Logo=211b4a71475a94e6aaec9cfa67a5354a.png, Location=GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines, StoreID=16, DeliveryAddress=Pavia Plaza, Pavia Plaza, Pavia, Iloilo, Philippines, SpecificAddress=test, ReqChangeAmount=3, AssignmentAccepted=0, OrderID=330, TransNo=5F1049A138847, Status=S, Pickup=0, Transpo=M}, {RefNo=0338, CartTotal=500, CustomerName=Jon Caesar Basco, MobileNo=09553174861, Urgency=Scheduled, DeliveryDateTime=2020-07-22 10:00:00, Logo=211b4a71475a94e6aaec9cfa67a5354a.png, Location=GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines, StoreID=16, DeliveryAddress=Wilson Street, Wilson St, Iloilo City Proper, Iloilo City, Iloilo, Philippines, SpecificAddress=test, ReqChangeAmount=445, AssignmentAccepted=0, OrderID=338, TransNo=5F16B18FE3B9A, Status=S, Pickup=0, Transpo=M}, {RefNo=0340, CartTotal=3920, CustomerName=Kb Villar, MobileNo=31949, Urgency=Scheduled, DeliveryDateTime=2020-07-23 07:00:00, Logo=211b4a71475a94e6aaec9cfa67a5354a.png, Location=GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines, StoreID=16, DeliveryAddress=Wilson Street, Wilson St, Iloilo City Proper, Iloilo City, Iloilo, Philippines, SpecificAddress=ksks, ReqChangeAmount=6080, AssignmentAccepted=0, OrderID=340, TransNo=5F17EDECEFA41, Status=S, Pickup=1, Transpo=M}, {RefNo=0345, CartTotal=500, CustomerName=Jon Caesar Basco, MobileNo=09553174861, Urgency=Express, DeliveryDateTime=2020-07-25 18:00:00, Logo=211b4a71475a94e6aaec9cfa67a5354a.png, Location=GoveSmart Solutions, Inc., Luna Street, Lapaz, Iloilo City, Iloilo, Philippines, StoreID=16, DeliveryAddress=Wilson Street, Wilson St, Iloilo City Proper, Iloilo City, Iloilo, Philippines, SpecificAddress=test, ReqChangeAmount=63, AssignmentAccepted=0, OrderID=345, TransNo=5F1BF3DC32C11, Status=S, Pickup=0, Transpo=M}]
The json is invalid. Where does it come from?

Please post the full return (j.GetString): write the result to disc and post the written filecontent.
Based on the error the jsonfile is Invalid.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
you see this part? this is json. note all the quotes and the separating ":"
B4X:
{
"status": true,
"data": [
{
"RefNo": "0253",
"CartTotal": "1000",
"CustomerName": "Kb Villar",
"MobileNo": "31949",
"Urgency": "Express",
....

you see this part? this is NOT json. note there are no quotes and the "=" instead of a ":" as separator.

B4X:
[{RefNo=0253, CartTotal=1000, CustomerName=Kb Villar, MobileNo=31949, Urgency=Express, DeliveryDateTime=2020-06-25 16:00:00,

all those "="'s are wrong. not json. how did you get from json to not json?? how did you get the first part? the correct part?

-----------------------------------------------------------------
next case: the code
snippet of your code:

B4X:
        jp.Initialize(job.GetString)
        map1 = jp.NextObject
        jg.Initialize(map1)
        Log(jg.ToPrettyString(2))
      
        If map1.Get("status") <> False Then
          
            If map1.Get("data") <> Null Then
                Private jp2 As JSONParser
                Private m As Map
              
                Log(map1.Get("data"))
              
                jp2.Initialize(map1.Get("data"))
                m = jp2.NextObject

should be:

B4X:
Dim json As JSONParser
json.Initialize(job.getstring)
Dim walker As Map = json.NextObject
Log("status: " & walker.Get("status"))
  
Dim list As List = walker.Get("data")
Log(list.Size & " items")
for each record as map in list
   ' do something with each record retrieved from list
   ' eg record.get("RefNo")
   '      record.get("CartTotal")
   '      etc
next

you already had a jsonparser. i don't know what you thought you were doing declaring a second one on the same object.
testing for status false is fair enough, but testing for data = null is not going to happen, and i don't think it's what you were looking for. data could be [] but not null. if you have to test for something, you want to test for size of data (0 = no records).
 
Last edited:
Upvote 0
you see this part? this is json. note all the quotes and the separating ":"
B4X:
{
"status": true,
"data": [
{
"RefNo": "0253",
"CartTotal": "1000",
"CustomerName": "Kb Villar",
"MobileNo": "31949",
"Urgency": "Express",
....

you see this part? this is NOT json. note there are no quotes and the "=" instead of a ":" as separator.

B4X:
[{RefNo=0253, CartTotal=1000, CustomerName=Kb Villar, MobileNo=31949, Urgency=Express, DeliveryDateTime=2020-06-25 16:00:00,

all those "="'s are wrong. not json. how did you get from json to not json?? how did you get the first part? the correct part?

-----------------------------------------------------------------
next case: the code
snippet of your code:

B4X:
        jp.Initialize(job.GetString)
        map1 = jp.NextObject
        jg.Initialize(map1)
        Log(jg.ToPrettyString(2))
     
        If map1.Get("status") <> False Then
         
            If map1.Get("data") <> Null Then
                Private jp2 As JSONParser
                Private m As Map
             
                Log(map1.Get("data"))
             
                jp2.Initialize(map1.Get("data"))
                m = jp2.NextObject

should be:

B4X:
Dim json As JSONParser
json.Initialize(job.getstring)
Dim walker As Map = json.NextObject
Log("status: " & walker.Get("status"))
 
Dim list As List = walker.Get("data")
Log(list.Size & " items")
for each record as map in list
   ' do something with each record retrieved from list
   ' eg record.get("RefNo")
   '      record.get("CartTotal")
   '      etc
next

you already had a jsonparser. i don't know what you thought you were doing declaring a second one on the same object.
testing for status false is fair enough, but testing for data = null is not going to happen, and i don't think it's what you were looking for. data could be [] but not null. if you have to test for something, you want to test for size of data (0 = no records).

Thank you so much for your response.

How was I able to get from JSON to no JSON.


B4X:
 If job.Success Then
        Private jp As JSONParser
        Private map1 As Map
        Private jg As JSONGenerator
        
        jp.Initialize(job.GetString)
        
        map1 = jp.NextObject
        
        jg.Initialize(map1)
        
        Log(jg.ToPrettyString(2))  'the JSON part
        
        If map1.Get("status") <> False Then
            
            If map1.Get("data") <> Null Then
                Private jp2 As JSONParser
                Private m As Map
                
                Log(map1.Get("data")) 'no JSON

Since I was trying to see why it's giving me an error. Also, I think you have answered this already, when you mentioned regarding the second parser.
Also, the I did the 2nd parser on the Sub before the one with the error, and it worked. So I just did the same. I will heed your advise and work from there.
 
Upvote 0
Top