0
我使用改裝2.0和我有令牌和帳戶及響應我得到一個包含數組列表Android的改造2.0找問題
響應的結構的JSONObject的POST請求如下
{
"communities": [
{
"commId": 1,
"name": "Enginnering"
},
{
"commId": 2,
"name": "Student"
},
{
"commId": 3,
"name": "Banking"
},
{
"commId": 4,
"name": "Teacher"
},
{
"commId": 5,
"name": "Government"
},
{
"commId": 6,
"name": "Political"
}
]
}
的模型類結構如下
CommunityModel implements Serializable{
public static final String KEY_COMMUNITY_ID = "commId";
public static final String KEY_COMMUNITY_NAME = "name";
public static final String KEY_CREATED_AT="c_at";
public static final String KEY_UPDATED_AT="u_at";
public static final String KEY_AUTHORIZATION = "Authorization";
public static final String KEY_COMMUNITIES="communities";
@SerializedName(KEY_COMMUNITY_ID)
int communityid;
@SerializedName(KEY_COMMUNITY_NAME)
String communityName;
@SerializedName(KEY_CREATED_AT)
String createdAt;
@SerializedName(KEY_UPDATED_AT)
String updatedAt;
public CommunityModel(int communityid, String communityName, String createdAt, String updatedAt)
{
this.communityid=communityid;
this.communityName=communityName;
this.createdAt=createdAt;
this.updatedAt=updatedAt;
}
public int getCommunityid() {
return communityid;
}
public void setCommunityid(int communityid) {
this.communityid = communityid;
}
public String getCommunityName() {
return communityName;
}
public void setCommunityName(String communityName) {
this.communityName = communityName;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
public String getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(String updatedAt) {
this.updatedAt = updatedAt;
}
}
我的改型接口
@FormUrlEncoded
@POST("/v1/communities/")
Call<ArrayList<CommunityModel>> getCommunities(
@Query(CommunityModel.KEY_AUTHORIZATION) String servertoken,
@Field(UserAccount.KEY_USER_ID) int type,
@Field(CommunityModel.KEY_COMMUNITIES) ArrayList<CommunityModel>communityList
);
我改造助手得到的ArrayList是如下
public ArrayList<CommunityModel> getcommunities() {
final ArrayList<CommunityModel> returnCommunityList = new ArrayList<>();
//final int userId = mIntent.getIntExtra(UserAccount.KEY_USER_ID, 0);
final String serverToken ="Basic"+" "+localSession.getServerToken();
DebugLog.i(NetworkOperationService.class.getSimpleName(), "servertoken"+serverToken);
Call<ArrayList<CommunityModel>> communityCall = mNetworkOperation.getCommunities(serverToken, localSession.getUserId(),);
communityCall.enqueue(new Callback<ArrayList<CommunityModel>>() {
@Override
public void onResponse(Call<ArrayList<CommunityModel>> call, Response<ArrayList<CommunityModel>> response) {
DebugLog.i(NetworkOperationService.class.getSimpleName(), "servertoken"+serverToken+"userid="+localSession.getUserId());
if (response!=null && response.code()==200)
{
DebugLog.i(NetworkOperationService.class.getSimpleName(), "200");
ArrayList<CommunityModel> arrayList = response.body();
for (int i=0;i<arrayList.size();i++)
{
returnCommunityList.add(arrayList.get(i));
DebugLog.i(NetworkOperationService.class.getSimpleName(), arrayList.get(i).getCommunityName());
}
}
else{
DebugLog.i(NetworkOperationService.class.getSimpleName(), "respose code"+response.code());
}
}
@Override
public void onFailure(Call<ArrayList<CommunityModel>> call, Throwable t) {
}
});
return returnCommunityList;
}
任何幫助,將不勝感激......我不能夠獲得響應... i灣以同樣的方式迴應如上面給出...
請幫助
任何錯誤?請添加日誌 –
我收到錯誤400 ...因爲它接受頭認證....所以現在我已經添加頭給它的迴應...我想知道查詢()參數和頭() –