Hi all
am working on an online database application.
I have a table contains only phone_number and ID
I use this code to get all the phone numbers and IDs and put them into 2 lists (ls1 and ls2) :
the code is working very well when there is fields in the table, but when the table is empty I get this error :
java.lang.RuntimeException: JSON Array expected.
thanks in advance
am working on an online database application.
I have a table contains only phone_number and ID
I use this code to get all the phone numbers and IDs and put them into 2 lists (ls1 and ls2) :
B4X:
Sub check_for_all_phones_and_IDs
Dim GetPersons As HttpJob
GetPersons.Initialize("GetP", Me)
GetPersons.download2("http://newg.com.sd/b4atest/users/checkphone.php", Array As String ("id", "phone_num"))
End Sub
Sub JobDone(Job As HttpJob)
ProgressDialogHide
If Job.Success Then
Dim res As String
res = Job.GetString
Dim parser As JSONParser
parser.Initialize(res)
ls1.Clear
Select Job.JobName
Case "GetP"
Dim ListOfPersons As List
Dim PersonName As String
Dim PersonAge As String
ListOfPersons = parser.NextArray 'returns a list with maps
If ListOfPersons.Size=0 Then
' no results
Else
For i = 0 To ListOfPersons.Size - 1
Dim Person As Map
Person = ListOfPersons.Get(i)
PersonAge = Person.Get("phone_number")
PersonName = Person.Get("id")
ls1.Add(PersonAge)
ls2.Add(PersonName)
Next
End If
Case "InsertP"
' Log(Job.GetString)
Case "dltID"
End Select
Else
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
the code is working very well when there is fields in the table, but when the table is empty I get this error :
java.lang.RuntimeException: JSON Array expected.
thanks in advance