B4J Question (Solved) (B4J WebApp) How to Parse JSON data come from Json.Stringify ?

pmt

Member
Licensed User
Hi,

I tried my own code base on the ServerJsonTree example.

This is my some code in index.html

B4X:
    var inq = {
            'data1'     : $("#f1").val(),
            'data2'        : $("#f2").val(),
            'data3'     : $('input[name=inputDate]').val(),
            'data4'        : $("#client").val()
        };       
        
        var jsond = JSON.stringify(inq);
        
        $.ajax({
             url:hostServer,
             type: "POST",
             data: {"action":'getquery',"page":$("#cppPage").val(),"data" : jsond}


This is from ServerJsonTree WebApp

B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    resp.ContentType = "application/json"
    resp.SetHeader("Access-Control-Allow-Origin","*")
    resMap.Initialize
    Try
        
            
'        Dim body As TextReader
'        body.Initialize(req.InputStream)
'        Log("xx:"&body.ReadAll)
        
        Dim data() As Byte = Bit.InputStreamToBytes(req.InputStream)
        Dim text As String = BytesToString(data, 0, data.Length, "UTF8") '
        Dim parser As JSONParser
        Log(text)
End Sub

I get log: (Why I got data like this ?)

action=getquery&page=0&data=%7B%22data1%22%3A%22VIP00001%22%2C%22data2%22%3A%22VIP00001%22%2C%22data3%22%3A%2215%2F02%2F2018%22%2C%22data4%22%3A%22127.0.0.1%22%7D

How to parse this data ?

Regards,
PMT
 
Top