欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

android okgo post传数组

程序员文章站 2022-10-25 12:43:32
JSONObject json1 = new JSONObject(); json1.put("memo", fankuiEt.getText().toString()); json1.put("userid",(int)sp.getSharedPreference(Constant.USERID,0));// 1个数组参数 JSONArray jsonArray = new JSONArray(); for (String tag : tags) ......

 JSONObject  json1 = new JSONObject();
        json1.put("memo", fankuiEt.getText().toString());
        json1.put("userid",(int)sp.getSharedPreference(Constant.USERID,0));

 // 1个数组参数
    JSONArray jsonArray = new JSONArray();
    for (String tag : tags) {
        jsonArray.put(tag);
    }
    json1.put("tags", jsonArray);

        Log.d("RegisterActivity", "json1: " + json1);
        MediaType JSON = MediaType.parse("application/json; charset=utf-8");
        RequestBody body = RequestBody.create(JSON, String.valueOf(json1));
        OkGo.<String>post(Urls.urlFankui)
                .upRequestBody(body)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                     
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                     
                    }
                });
 

本文地址:https://blog.csdn.net/qq_34895720/article/details/107098803