android - 如何在没有密钥的情况下从改造 JSON 中获取响应
问题描述
在我的retrofit JSON
响应中,single value
没有任何key and type
. 在我的 JSON 中,我根据需要传递了三个元素,现在我得到如下所示的响应。那么我怎样才能获取该响应?
我的JSON of Response
样子——
成功的
这是我的 JSON 代码-
private void ASSIGN_DATA() {
ApiInterface apiInterface=ApiClient.getClient().create(ApiInterface.class);
Call<ArrayList<price_get_set>> call=apiInterface.assignItemToJson(select_date.getText().toString(),
id,item_list);
call.enqueue(new Callback<ArrayList<price_get_set>>() {
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onResponse(Call<ArrayList<price_get_set>> call, Response<ArrayList<price_get_set>> response) {
progress.dismiss();
Log.d("URL::",response.toString());
Log.d("new URL::",response.body().toString());
try {
if (response.isSuccessful()) {
Toast.makeText(Items_List.this, "Successs", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Items_List.this, Item_Accept_Reject_List.class);
startActivity(intent);
}
else
Toast.makeText(Items_List.this, "Something went Wrong", Toast.LENGTH_SHORT).show();
}
catch (Exception ex){
Log.e("ERROR::",ex.getMessage());
}
}
@Override
public void onFailure(Call<ArrayList<price_get_set>> call, Throwable t) {
progress.dismiss();
Log.i("FAILURE ERROR::",t.getMessage());
}
});
}
解决方案
您可以使用response.body().string()
. 它会将您的响应转换为字符串。
示例在您onResponse
的 API 方法上,您必须使用此代码。
@Override
public void onResponse(Response<ResponseBody> response) {
try {
String responseString = response.body().toString();//This a response as string
Log.d("Response : " + responseString);
} catch (IOException e) {
e.printStackTrace();
}
}
推荐阅读
- ruby-on-rails - 嵌套属性并在一个控制器(父控制器)中创建两个独立模型的实例
- typescript - 在 typescript 中避免接口重复解析 JSON
- c# - 代码并不总是突出显示富文本框中的选定文本
- javascript - React 应用程序和 Laravel API 的 CORS 问题
- flutter - 异常:ideviceinfo 返回错误:错误:无法连接到锁定,错误代码 -17
- unity3d - AudioListener.pause = true 后暂停菜单音乐;
- java - 如何在没有小时的情况下解析 HH:mm:ss?
- html - 使剪辑路径与可拖动图像一起使用
- java - 避免方法调用 getLatitude 可能产生 java.Lang.NullPointerException
- javascript - JS:303后重定向查看其他