getjson作为改造2.0中的响应

时间:2016-03-17 09:42:11

标签: android json rest retrofit retrofit2

iam试图像这样得到json resopse但它带有不正确的json格式如何以正确的格式获取字符串

Call<HashMap<Object,Object>> call = RestClient.getClient().aladata(AppUtil.getAuthKey(DashboardActivity.this),String.valueOf(mSelectedCategory.getId()), String.valueOf(mLat), String.valueOf(mLng), String.valueOf(50), String.valueOf(offset * 50));
        call.enqueue(new Callback<HashMap<Object,Object>>() {
            @Override
            public void onResponse(Call<HashMap<Object,Object>> call, Response<HashMap<Object,Object>> response) {
                String hashMapString=response.body().toString();
                try {
                    JSONObject jsonObject=new JSONObject(hashMapString);
                    String jsonstr=jsonObject.toString();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                HashMap<Object,Object> hashMap2=response.body();
            }

            @Override
            public void onFailure(Call<HashMap<Object,Object>> call, Throwable t) {

            }
        });
}

1 个答案:

答案 0 :(得分:2)

使用Retrofit时,应使用JsonObject代替JSONObject

希望它有所帮助!