Retrofit Post:发送请求时获取斜杠

时间:2018-05-04 06:47:40

标签: android post retrofit

我正在使用Retrofit Post但是在向post方法发送数据时我得到斜杠()。这里我需要将完整的json对象数据发送到post方法,所以我将json对象转换为String。但是当发送斜杠时会附加请求。我也将斜杠替换为空字符串,但它不起作用。任何人请帮助我。

代码:

 private void favouriteadding(String restaurant_id, String restaurant_name, JsonArray Restaurant_info) {
        String replac = Restaurant_info.toString(); // jsonarray
        replac = replac.replace("[", "")
                .replace("]", "")
                .trim();
        Log.v("Tag_replacestring",""+replac);
        ServiceClient serviceClient = ServiceUtil.getServiceClient();
        JsonObject userfav = new JsonObject();
        userfav.addProperty("user_id", m_sharedPreference.getString("userid", ""));
        userfav.addProperty("restaurant_id", restaurant_id);
        userfav.addProperty("restaurant_name", restaurant_name);
        userfav.addProperty("restaurant_info",replac.replace('\\','"') );
        Log.v("Tag_postdata",""+userfav);
        serviceClient.list_fav(userfav, listfavcallback);
    }

日志:

 Tag_replacestring:   {"status":"enabled","features":"No Alcohol Available","cuisines":"Hyderabadi","Mughlai","Biryani","Chinese","cost":850.0,"createdAt":"2018-03-08 09:26:13","branch_id":"5aa146ce1d41c86e73e11d79","stats":{},"dishes":"Hyderabadi Dum Biryani","Mutton Biryani}

但是使用斜杠得到这样的结果: Tag_postdata:

{"user_id":"","restaurant_id":"5aa148051d41c86e73e11d7a","restaurant_name":"Hotel Shadab","restaurant_info":"{\"status\":\"enabled\",\"features\":\"No Alcohol Available\",\"cuisines\":\"Hyderabadi\",\"Mughlai\",\"Biryani\",\"Chinese\",\"cost\":850.0,\"createdAt\":\"2018-03-08 09:26:13\",\"branch_id\":\"5aa146ce1d41c86e73e11d79\"

0 个答案:

没有答案