Android 如何使用jackson注释解析jsonarray
问题是我无法解析简单的json数组 jsonarray的结构是:Android 如何使用jackson注释解析jsonarray,android,json,annotations,jackson,arrays,Android,Json,Annotations,Jackson,Arrays,问题是我无法解析简单的json数组 jsonarray的结构是: [{ "id": 1, "name": "name_1" }, { "id": 2, "name": "name_2" }] 我已尝试使用以下代码: @JsonIgnoreProperties(ignoreUnknown = true) public class MyObject { public String id; public String name; }
[{
"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()
{
}
}
Per:
简单类型定义为除一个已识别类型以外的任何类型
容器类型(数组、集合、映射)
听起来你想要一个。@bakriOnFire我使用了类似这样的东西:CollectionType.construct(ArrayList.class,SimpleType.construct(Committee.class));
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);
}
});
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)