2016-12-02 38 views
0

实际的请求是与改造面临的问题:2.1.0。它转换&和=运算unicode字符串

{ “反馈”: “机器人& 测试”, “形式”: “反馈”, “登录ID”: “XYZ123”}

改造转换&运营商为Unicode

{ “反馈”: “的Android \ u0026 测试”, “形式”: “反馈”, “登录ID”: “XYZ123”}

请帮我解决这个问题。

public interface APIView { 
@POST(URLS.FEED_BACK) 
Call<FeedbackResponse> saveFeedback(@Body FeedbackRequest request); 
} 

public class WebServices { 
private static WebServices instance = null; 
Gson gson; 
final OkHttpClient okHttpClient; 
Retrofit retrofit; 
APIView service; 

private WebServices() { 
    this.gson = new GsonBuilder().setDateFormat("yyyy-MM-  dd'T'HH:mm:ssZ").create(); 
    this.okHttpClient = new Builder().readTimeout(60, TimeUnit.SECONDS).connectTimeout(60, TimeUnit.SECONDS).build(); 
    this.retrofit = new  Retrofit.Builder().baseUrl(URLS.BASE_URL).addConverterFactory(GsonConverterFacto  ry.create(this.gson)).client(this.okHttpClient).build(); 
    this.service = (APIView) this.retrofit.create(APIView.class); 
    } 

    public static WebServices getInstance() { 
    if (instance == null) { 
     instance = new WebServices(); 
    } 
    return instance; 
    } 

    public APIView getService() { 
    return this.service; 
    } 
} 
+0

,请复制粘贴您的更新接口,你有那么我们可以帮助你任何拦截器。 – iagreen

+0

哎@iagreen具有u看到我的问题 – user3295685

回答

0

您需要在您的gson实例中禁用html转义。

this.gson = new GsonBuilder().disableHtmlEscaping().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create(); 
0

使用这样

{"feedback":"android &amp; testing","form":"Feedback","loginId":"xyz123"} 
0

我有同样的问题,我解决它转换请求url编码形式,然后再改了urlencoded请求到服务器端的实际要求:

String urlEncoded = ""; 
    try{ 
     urlEncoded = URLEncoder.encode(yourAwesomeRequest); 
    } 
    catch (Exception e){ 
     //OMG 
    } 

而在服务器端,将urlEncoded转换为实际的请求。