Android Question Translate java request to b4a

cliv

Member
Licensed User
Longtime User
B4X:
    public String checkCod(String sCod) {
        JSONParser jsonParser = new JSONParser();
        try {
            List<NameValuePair> params = new ArrayList();
            params.add(new BasicNameValuePair("id", "2"));
            params.add(new BasicNameValuePair("key", "XXXXXXX"));
            params.add(new BasicNameValuePair("cod", sCod));
            JSONObject obj = jsonParser.makeHttpRequest(this.IP, params);
            if (obj.getString("status").toString().equals("1")) {
                return obj.getJSONObject("data").getString("content").toString();
            }
            return obj.getString("error_message").toString();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

How can i translate this to b4a?
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

cliv

Member
Licensed User
Longtime User
I know to parse json i want to translate sub code to b4a
B4X:
    Dim hc As HttpClient
    Sub Activity_Create(FirstTime As Boolean)

        hc.Initialize("hc")
 
        Dim post As HttpRequest
        Dim strReq As String
        strReq = "id=2" & "&key=XXXXXXX" & "&cod=" & sCod
        post.InitializePost2(IP, strReq.GetBytes("UTF8"))
        hc.Execute(post, 1)
    End Sub

I try this....
 
Upvote 0
Top