Android Question httpResponse Asynchronously and JSON

frutuopa

Member
Licensed User
Longtime User
Hello

I have B4A 2.22

Before i have a code like this

Sub hcimport_ResponseSuccess (Response As HttpResponse, tabela As Int)
Dim res As String
'Msgbox("sucesso","")
res = Response.GetString("UTF8")
Log("Response from server: " & res)
Dim parser As JSONParser
parser.Initialize(res)
Dim dadosget As List

dadosget = parser.NextArray 'returns a list with maps
'sql1.BeginTransaction
..................................................................................................


Now because GetString
is deprecated and will not work properly on Android 4+ device.
i try to use Use GetAsynchronously instead.

i do that:

Sub Process_Globals
Dim my_buffer As OutputStream
end sub

Sub hcimport_ResponseSuccess (Response As HttpResponse, tabela As Int)
Dim Res As String
Dim TaskId As Int
Msgbox("sucesso","")
my_buffer.InitializeToBytesArray(5000) ' I expect less than 2000 bytes here
Msgbox("sucesso","")
Response.GetAsynchronously("Response",my_buffer,True,TaskId)
End Sub

Sub Response_StreamFinish (Success As Boolean, TaskId As Int)

Msgbox (my_buffer,"")
Log("Response from server: " & my_buffer)
Dim tabela As Int

Dim parser As JSONParser
parser.Initialize(my_buffer)

Dim dadosget As List
Dim conty,contx As Int
'Dim tid As Int
'Dim tcodigo As Int
'Dim tnome As String
'Dim tnomereduzido As String
Dim vsql As String
Dim stabela As String
tabela=1


dadosget = parser.NextArray 'returns a list with maps

..............................................................................


i have an error "JSON Array expected".....
I undestand because the first line begin with (ByteArrayOutputStream)

.............................................................................................................
Response from server: (ByteArrayOutputStream)
[{"id":"2","codigo":"1001","nome":"Carter Chapeu 003 F1A","nomereduzido":"CC-003"},{"id":"69","codigo":"1068","nome":"CARTER CILINDRO 180","nomereduzido":"CC-180"},{"id":"90","codigo":"1087","nome":"CARTER CILINDRO 220","nomereduzido":"CC-220"}]


CAN YOU HELP ME

Thanks
 
Top