Android Question how to check if json object is empty

Makumbi

Well-Known Member
Licensed User
Longtime User
How can i check if there is no record returned by Json
B4X:
cursor1 = Starter.SQL1.ExecQuery("SELECT phone AS Phone FROM Register")
    If cursor1.RowCount > 0 Then
    '    For i = 0 To cursor1.RowCount - 1
            cursor1.Position =0
            Dim phone As String
            phone = cursor1.Getstring("Phone")
        'Next
    End If
    Dim CustID As String = phone' Customer ID
    Dim j As HttpJob
    j.Initialize("", Me)
    'j.Download("http://192.168.1.239/WebServicesula/Service.asmx/Get")
    j.Download("http://192.168.1.239/Generic_Handler_JSON/HandlerVBPay.ashx?customerid=" & CustID)
    'j.Download("http://192.168.1.239/Generic_Handler_JSON/HandlerVB.ashx")
    'j.PostString("http://192.168.1.239/Webandroid//VB.aspx?customerid=" & CustID)
    
    j.GetRequest.Timeout = 10000 ' 10 seconds
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then ' if job is success (http status code 200)
        Dim RetVal As String
        RetVal = j.GetString
        
        Dim jp As JSONParser
        jp.Initialize(j.GetString)
        Log(jp) ' will pr
        Dim quotes As List = jp.NextArray
        For Each quot As Map In quotes
            Log("CustomerId: " & quot.Get("CustomerId"))
            Log("Name: " & quot.Get("Name"))
            Log("Class: " & quot.Get("Class"))
            Log("Stream: " & quot.Get("Stream"))
            Log("Amount: " & quot.Get("Amount"))
            Log("Dates: " & quot.Get("Dates"))
            Log("Years: " & quot.Get("Years"))
            Log("Term: " & quot.Get("Term"))
            Log(DateTime.Date(JsonDateToTick( quot.Get("Dates"))))
            Dim l As Long
            DateTime.DateFormat = "dd/MM/yyyy" ' "1961-08-29"
            Dim datestring As String = DateTime.Date(JsonDateToTick( quot.Get("Dates")))
            l = DateTime.DateParse(datestring)
            DateTime.DateFormat = "dd/MM/yyyy"
            Log(DateTime.Date(l))
            'Grab the last ID number which is the highest number
            cursor1 = Starter.SQL1.ExecQuery("SELECT id FROM student")
            'cursor1 = SQL1.ExecQuery("SELECT Phone FROM Register")
            If cursor1.RowCount > 0 Then
                For i = 0 To cursor1.RowCount - 1
                    cursor1.Position = i
                
                    Dim NewID As Int
                    NewID = cursor1.GetInt("id")
                Next

            End If
            NewID = NewID +1      ' add 1 to the ID number to make a new ID field
    
            Starter.SQL1.ExecNonQuery("INSERT INTO student VALUES('" & quot.Get("CustomerId") & "','" & quot.Get("Names") & "','" & quot.Get("Class") & "','" & quot.Get("Stream") & "','" & quot.Get("Amount") & "','" &  DateTime.Date(l) & "','" & NewID & "','" & quot.Get("Years") & "','" & quot.Get("Term") & "')")
        Next
        Else
        Msgbox("Records Not Processed. Please check Internet Connectivity and Try Try Again ","No Records Returned")
    End If
        Msgbox("Records Processed Successfully. You Can Now Check ","SMIS")
    Log(RetVal) ' will print in log value returned from the server
    j.Release
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
What does it print? The first line or the second? I guess the second. you can check if job.gestring <> "[]"

Where does the 1st line come from??? If it part of job.gestring. if yes then it is a output from the webservice. Change the output of the webservice. It should be inside the output of the webservice.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I suggest to get some coding books and read them
I also suggest to read the B4X Language Books and read them. More of all: Understand what you are reading there.

What is the problem? You don´t know how to compare one string with another and create a IF THEN ELSE END IF structure for this?

B4X:
if j.GetString = "[]" then
  log("JSON epmpty!!!")
else
  log("JSON not epmpty, parse it")
  Dim jp As JSONParser
  jp.Initialize(j.GetString)
  ' your parsing code here
end if
 
Last edited:
Upvote 0

Similar Threads

Replies
19
Views
4K
Replies
36
Views
121K
  • Locked
  • Article
Android Tutorial Google Maps
Replies
192
Views
173K
Top