问题在于我无法解析一个简单的json数组
jsonarray的结构是:
[{
"id": 1,
"name": "name_1"
}, {
"id": 2,
"name": "name_2"
}]
我尝试过以下代码:
@JsonIgnoreProperties(ignoreUnknown = true)
public class MyObject
{
public String id;
public String name;
}
public class RouteServerResponse extends ArrayList<MyObject>
{
public RouteServerResponse()
{
}
}
请求数据的方法是:
final JacksonRequest<RouteServerResponse> request = new JacksonRequest<RouteServerResponse>(Request.Method.GET, url, params,
new JacksonRequestListener<RouteServerResponse>()
{
@Override
public void onResponse(RouteServerResponse r, int statusCode, VolleyError error)
{
if (c != null)
c.onResponse(r, statusCode, error);
}
@Override
public JavaType getReturnType()
{
return SimpleType.construct(RouteServerResponse.class);
}
});
我在logcat
中收到此错误11-14 19:06:08.708 27593-28098/ru.youroute E/Volley﹕ [3991] NetworkDispatcher.run: Unhandled exception java.lang.IllegalArgumentException: Can not construct SimpleType for a Collection (class: ru.youroute.model.serverresponse.impl.RouteServerResponse)
java.lang.IllegalArgumentException: Can not construct SimpleType for a Collection (class: ru.youroute.model.serverresponse.impl.RouteServerResponse)
答案 0 :(得分:2)