1
的問題是,我無法分析一個簡單的JSON陣列如何分析jsonarray使用傑克遜註釋
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)
謝謝,賈斯汀。 所有現在正在 – 2014-11-14 16:16:24
能否請您explain..how你實現這個.. – bakriOnFire 2015-10-15 07:28:27
@bakriOnFire我以前是這樣的: CollectionType.construct(ArrayList.class,SimpleType.construct(Committee.class)); – 2015-10-15 10:01:26