B4R Question ESP8266 - reading JSON from PHP on the web

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends,

please, I can read JSON output from PHP on the web with ESP8266?

my first step is :
trying standard way as in B4J, but I see that it is not good way because of library...it strue?

B4X:
Sub Go
    Dim req As HttpRequest
    req.InitializeGet("http://xxxx.xxx/yyyy/zzzz.php?" & "id=" & id)
    httpC.Execute(req,1)
End Sub

Sub httpC_ResponseSuccess (Response As HttpResponse, TaskId As Int)
 If Taskid=1 then
  'here I will work with JSON
        Dim result As String
        Dim JSON As JSONParser
        Dim restOpen As Int
        result = Response.GetString("UTF8")
 End if
End Sub

Please for advice what is the best direction for working with PHP json output in ESP8266
Best regards
p4ppc
 

petr4ppc

Well-Known Member
Licensed User
Longtime User
I go to learn how to work with jOkHttpUtils2 in B4R and in B4J I will rework my project step by step,
thank you Erel,
Best regards
p4ppc
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends,

with this
B4X:
bc.SubString2(Job.Response, 0, Min(200, Job.Response.Length))
I get in logs JSON output from php file, I get this:
[{"id":"1","yesno":"0","text":"Something"}]

I am reading this: https://www.b4x.com/android/forum/threads/strings-and-bytes.66729/#content

but please I am doing some mistake:
B4X:
Sub JobDone (Job As JobResult)
  Dim bc As ByteConverter
  Log("Response: ", bc.SubString2(Job.Response, 0, Min(200, Job.Response.Length))) 'truncate to 200 characters
 
 Dim jsontext() As Byte
 jsontext()=bc.SubString2(Job.Response, 0, Min(200, Job.Response.Length))

this is wrong declaration I know,
but how can I solve the row:
B4X:
jsontext()=bc.SubString2(Job.Response, 0, Min(200, Job.Response.Length))

Thank you
p4ppc
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
I have error message (over mouse cursor) : Missing parameter.

Here:
B4X:
jsontext()=bc.SubString2(Job.Response, 0, Min(200, Job.Response.Length))

Error:
jsontext()=bc.SubString2(Job.Response,0,Min(200,Job.Response.Length))
Word: (
Please for advice,
thank you,
p4ppc
 
Last edited:
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Thank you very much,

it was my mistake, because in my tests I rewrite
B4X:
Dim jsontext() As Byte
to
B4X:
Private jsontext() As Byte
and this give me mistake,

Thank you very much
Best regards
p4ppc
 
Upvote 0
Top