Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用jackson注释解析jsonarray_Android_Json_Annotations_Jackson_Arrays - Fatal编程技术网

Android 如何使用jackson注释解析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; }

问题是我无法解析简单的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()
    {

    }
}
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)