2017-03-03 81 views
0

你好,我必須通過JSON獲取方法的URL,我已經使用了翻新庫。UrlEncoder編碼的字符串不工作?

http://jbossdev- *****。*****。com/****/web/rest/waitlistRestAction/checkinusers?orgid = 2 & pagerReqParam = {「filters」:null,「sort」:null 「中將sortOrder」:空 「的pageSize」:500, 「您做生意」:1}

欲編碼JSON是 { 「過濾器」:空, 「排序」:NULL, 「中將sortOrder」:空, 「pageSize的」:500, 「您做生意」:1}

正確的編碼:。

http://jbossdev- ***** ***** COM/kyobee /網絡/休息/ waitlistRestAction/checki nusers ORGID = 2 & pagerReqParam =%7B%22filters%22:空,%22sort%22:空,%22sortOrder%22:空,%22pageSize%22:500,%22pageNo%22:1%7D

在URL傳遞編碼字符串後,我得到了

http://jbossdev- *****。*****。com/***** /網絡/ REST/waitlistRestAction/checkinusers?ORGID = 2 & pagerReqParam = %257B%2522filters%2522%253Anull%252C%2522sort%2522%253Anull%252C%2522sortOrder%2522%253Anull%252C%2522pageSize%2522%253A500%252C%2522pageNo%2522%253A1%257D

@GET(General.CHECK_IN_USERS) 
    Call<CheckInUsers> checkInUsers (@Query(ORG_ID) String orgId , @Query(PAGER_REQ_PARAM) String pagerReqParam); 


String query = URLEncoder.encode (reqParam, "WINDOWS-1252");   
      mAPIService = General.getClient().create (APIService.class); 
      Call<CheckInUsers> checkInUsersCall = mAPIService.checkInUsers (orgId, query); 
      checkInUsersCall.enqueue (new Callback<CheckInUsers>(){ 
       @Override 
       public void onResponse (Call<CheckInUsers> call, Response<CheckInUsers> response){ 
} 

回答

0

與此類似。如果您已實現的接口,嘗試用encoded = true所需參數

例子:

public interface APIInterface { 

    @GET ("loginapi.php") 
    @Headers({"Content-Type: application/x-www-form-urlencoded"}) 
    Call<LoginPOJO> loginResponse(
            @Query(value = "password",encoded = true) String password, 
            @Query(value = "key",encoded = true) String key, 
            @Query(value = "uid",encoded = true) String uid, 
            @Query(value = "email", encoded = true) String email 
           ); 
}