【发布时间】:2022-01-13 07:16:37
【问题描述】:
请求帮助,我正在尝试从 API 获取 JSON 响应,响应 not null 并且有点长,因为它具有 Base64 编码的图片数据This is the fragment from the response
这是我用来获取 JSON 响应并将其转换为 JSONArray 的部分代码
StringRequest reqMasterDataShift = new StringRequest(Request.Method.GET, ActionUrl.LastShift+"/"+siteCode,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try{
JSONObject jsonObject = new JSONObject(response);
JSONArray shift = jsonObject.getJSONArray("shift");
JSONArray shiftPhoto = jsonObject.getJSONArray("shift_photo"); // Method threw 'java.lang.StackOverflowError' exception. Cannot evaluate org.json.JSONObject.toString()
Timestamp currentTime = new java.sql.Timestamp(System.currentTimeMillis());
ObjectMapper mapper = new ObjectMapper();
ArrayList<ShiftModel> shiftData = new ArrayList<>();
shiftData = mapper.readValue(shift.toString(), new TypeReference<ArrayList<ShiftModel>>() {});
ArrayList<ShiftPhotoModel> shiftPhotoData = new ArrayList<>();
shiftPhotoData = mapper.readValue(shiftPhoto.toString(), new TypeReference<ArrayList<ShiftPhotoModel>>() {});
.
.
...
衷心希望您对此问题的帮助或解决方案,非常感谢您的 cmets 或一些建议,谢谢!
【问题讨论】:
-
您可以发布整个响应正文吗?
-
@GuanHongHuang 看这里pastelink.net/4mvwm1ns
标签: java android arrays json android-studio