iOS Question Response.GetString error

jaraiza

Active Member
Licensed User
Longtime User
I'm getting crazy LOL Any kind of routine I used in B4A is failing on me :)

B4X:
Sub host_ResponseSuccess (Response As HttpResponse, TaskId As Int)
   Dim Receive as String
   Receive = Response.GetString("UTF8")
End Sub
A get an error on response line -> "Array Expected"

Did anything changed in iHttp library?

Thanks!
 
Last edited:

jaraiza

Active Member
Licensed User
Longtime User
Here's the full code if needed (This code works 100% on B4a):

Just call hostLoad("PieceOfName")

Ex: If you are looking for George Smith, call -> hostLoad("orge")

B4X:
Sub hostLoad (NameChunk As String)
    hostAddress      = "http://www.site.com/folder/spinnFill.aspx"
    Transmit        =     hostAddress & "?bite=" & NameChunk

    Request.InitializeGet(Transmit)
    Request.Timeout = 100
    HD.ProgressDialogShow("Searching for matching names...")
    host.Execute(Request, task_Lugares)
End Sub
Sub host_ResponseSuccess (Response As HttpResponse, TaskId As Int)

    HD.ProgressDialogHide

    Dim Receive As String  = Response.GetString("UTF8")
   
    Log("Response from server: " & Receive)

    Dim JSON As JSONParser
    JSON.Initialize(Receive)
   
    Map1 = JSON.NextObject

   
    MenuItems = Map1.Get("afiliados") ' Nodo principal (Mapa)
   
    Dim MenuISize As Int = MenuItems.Size

    If MenuISize > 0 Then
        For i = 0 To MenuISize - 1
            Map1 = MenuItems.Get(i)
            Log(Map1.Get("name"))
        Next
    Else
        ' NO RESULTS
    End If

    'Log (MenuItems.Size)
End Sub
Sub host_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
    Dim msg As String

    HD.ProgressDialogHide

    msg = "Server Error"
    If Reason <> Null Then msg = msg & CRLF & Reason
    Msgbox (msg,"Notification")
End Sub

I've tried to removing "UTF8" and then I'm allowed to compile, but the app hangs at "Searching for matching names..."
 
Upvote 0

jaraiza

Active Member
Licensed User
Longtime User
Why aren't you using HttpUtils2?

Can you upload your project?
Hi!

Well, I'm not using HttpUtils2 for JSON because I've my code snippet since a long time ago and it works, but if you can enlightenment me I'd be grateful ;)

If you need the real URL I can send it to your inbox.

Thanks!
 

Attachments

  • JSON Example.zip
    26.3 KB · Views: 290
Upvote 0

jaraiza

Active Member
Licensed User
Longtime User
Yeah, that's the problem, the program freezes there, it never gets "host_ResponseSuccess" or "host_ResponseError" even I if set the timer very low (Request.Timeout = 100)

When I run the same code on B4A it reads the data in a jiffy and jumps to host_ResponseSuccess Sub.
 
Upvote 0

jaraiza

Active Member
Licensed User
Longtime User
BTW, in the code I changed the line "Response.GetString("UTF8")" to "Response.GetString()", if I include "UTF8" I get an error:

B4X:
Compiling code.                         Error
Error compiling program.
Error description: Array expected.
Occurred on line: 70
Dim Receive As String  = Response.GetString("UTF8")
 
Upvote 0
Top