84669 Lernen von Personen
152542 Lernen von Personen
20005 Lernen von Personen
5487 Lernen von Personen
7821 Lernen von Personen
359900 Lernen von Personen
3350 Lernen von Personen
180660 Lernen von Personen
48569 Lernen von Personen
18603 Lernen von Personen
40936 Lernen von Personen
1549 Lernen von Personen
1183 Lernen von Personen
32909 Lernen von Personen
retrofit中gsonconverter 对于空集合 array:[] 这种解析会报错 请问有什么解决办法吗
认证高级PHP讲师
自定义类继承Converter.Factory,改写convert()方法如下:
Converter.Factory
convert()
@Override public T convert(ResponseBody value) throws IOException { String response = value.string(); try { return gson.fromJson(response, type); } catch (JsonSyntaxException e) { try { org.json.JSONObject json = new org.json.JSONObject(response); String data = json.getString("data"); if (TextUtils.isEmpty(data) || data.equals("[]")) { // 添加对空Json数组的处理逻辑 } } catch (JSONException e1) { // no op } throw new ApiException(ApiException.JSON_PARSE_ERROR, ApiException.JSON_PARSE_ERROR_MESSAGE); } finally { value.close(); } }
自定义类继承
Converter.Factory
,改写convert()
方法如下: