iOS Question Help Parser.NextObjetc

Andre Souza

Member
Licensed User
Please help me in converting this code to B4i. On the B4A, it works perfectly.

The function registers a user in the MYSQL database, returning as value by PHP, only the ID number.

B4X:
        If Job.JobName = "InserirUsuario" Then
            Valor = Parser.NextObject
            Dim ValorInt As Int
            If IsNumber(Valor) Then
                ValorInt = Valor
                If ValorInt > 0 Then
                    IDGerado = ValorInt
                    CadastroUsuarioFinal(IDGerado)
                Else
                    HD.ToastMessageShow(CST.MENSAGEM_CADASTRO_ERRO, False)
                End If
            Else
                HD.ToastMessageShow(CST.MENSAGEM_CADASTRO_ERRO, False)
            End If
        End If

The value of the "Value" variable must return a number.

But it has an exception Error parsing string: Error Domain = NSCocoaErrorDomain Code = 3840 "JSON text did not start with array or object to allow fragments not set." UserInfo = {NSDebugDescription = JSON text did not start with array or option to allow fragments not set.}
 

tufanv

Expert
Licensed User
Longtime User
Hello.
O value output is um number ID (Ex. 1345899)
Replace with Job.GetString is working. What is method correct?
As I can see you used
B4X:
Valor = Parser.NextObject

but where is the parser is initialized ? you must use parser.initialize(job.getstring)

only than you can use for example
B4X:
dim l as list
l=parser.nextobject

if you are meaning this .
 
Upvote 0

Andre Souza

Member
Licensed User
I solved the problem using only the Job.String

B4X:
If Job.JobName = "InserirUsuario" Then
            Valor = Job.String
            Dim ValorInt As Int
            If IsNumber(Valor) Then
                ValorInt = Valor
                If ValorInt > 0 Then
                    IDGerado = ValorInt
                    CadastroUsuarioFinal(IDGerado)
                Else
                    HD.ToastMessageShow(CST.MENSAGEM_CADASTRO_ERRO, False)
                End If
            Else
                HD.ToastMessageShow(CST.MENSAGEM_CADASTRO_ERRO, False)
            End If
        End If
 
Upvote 0
Top