当前位置: 首页 > 面试题库 >

GSON预期为BEGIN_ARRAY,但为BEGIN_OBJECT

东郭良弼
2023-03-14
问题内容

我在列表中仅收到一个项目时收到此错误。我在服务器端REST Web服务中使用Jersey,当List返回一个元素并且当0elements我得到它时,我仅收到错误,java.lang.NullPointerException但是当它包含多个元素时,它可以正常工作,这就是我的工作方式它:

@GET
@Path("getproject")
@Produces(MediaType.APPLICATION_JSON)
public List<Project> getPagedProjects(
       @QueryParam("offset") int offset,
       @QueryParam("limit") int limit,
       @QueryParam("searchKey") String searchKey) throws Exception {

  System.out.println("Returning Paged Project ");
  return projectService.getPagedProjects(offset, limit, searchKey);
}

为什么Jersey不发送包含一个项目的列表?这是球衣的虫子吗?有没有办法使它始终序列化为数组?

当Web服务返回0元素时,这是我的JSON数据:

null

当Web服务返回1元素时,这是我的JSON数据:

{
    "project": {
        "abbreviation": "abc",
        "customer": "customer1",
        "description": "description3",
        "icon": "iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAN4UlEQVR42u2ZeXBUx53Hx8FgSAIWMiB0jO7RLRkwbFxxnC1ntyp/JXbh9TrmirEDOpA4JQQ6kdCBDiQOU65UjNdO2djYGLCzKRJjY841SJoZzaEZaTSjc0b3hST0JCH5u79fa54YCZLUZteurQpTfKq7X/f0+35//et+b4RC8fDz8PPw8/Dz8PMP/ykoKFBkZmY+evLkyR9//PHHr545c2azC6/9BUQ/jd/w4Ycf/uLNN9+M3r179w8AKNzd3b878eXl5QoSoXjnnXd+ZjAYmjo7Oye6uromme7u7m+coKenR+YbF3jcWHt7+2B9fX3r1atXP3777befW7du3aOpqanfjYGysjJFY2Oj4uzZszt6e3sxOjoqGBu/i7sTE8QkJia/EdC/aeRr3D9+9y7Gx8cxPDyM2tpaO821JysrayHP/Z0YuH37tuLcuXO7+vr6vpEN9LZa4DBcQ5vxGjpqrqOz5ga6TIT5Brpd6K27hZGBboyNjU2bdzgcdy5duvS7N954I4Ru8ciWLVu+XQMDAwO8Ajv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B79Ov8J16sOrj0fgO1t87QQ+xpEruGIvwULDtXoX73CopwDEU4Cs37wtGaHgpHpgrt2UEkOADdtLw9+X7oLfBDP0VqgG5yu1iJ2yVKDJb6YPAw442hMq8pyj2J5YQHBo8wy3BbsBQDRH/5MvQRvWUe6C7zRNdhL3SWeqOjhFaM5rQd8hq6nrfs2Ru5HorpTUwGktiA8dJJGPf/CJZdq1G/5ynK55VoTI1BC71d2jPC0J4VQqKDSXQgiQ5AHy3pwCF/EuyPwRJ/DJX6Y/iwP+6U+WOknDjiD4k56kf4QjrG+BDeGDnmhZHjywkP3Dm+DMOCpRg8thS3iYGjZISM9ZLZHjLeRYHopIBYCpWdFzO9Ij7P9FIo+M9zly9fZgNxJtoD2j8chyl1DazJT9FGXEkRj6aIR1DEQ9FxQIWu3CD05AWS8AAMFJLoogAMlQRguDQAI4cDIZUFYbQ8GGNHVEQIxo+GTnGM6sdURBDGjwcQfhg7riS8MXrcExKZGCEDd8gAM3RsCQaP8orwalC6lVF60SqyAWNOkPmjXdE+Z5IjFYpHHnmE/8Y7JyUl5blz5z81/fH3x6Qvdv5Y+q9tMdLNpCjp1vYIqXJnuKTeFSpp94RIumSVpE9RSYa9wVJNarBk2qeSzPtVUm1aiFSXHirVZ4RJ1swIyZYZKTVkRUkN2TFSoyCa6tyOIMIkW3aIZM0OluqzA4kAyZLlL9Vl+UrmTF/JlKmUTBlKyUgY0pWSPt1Xqk7zk7T7/aVbe4PunI6NPLlS5fME61bMmTPne4899pj7ggULVq9Zs+bVtS+8sO+lf3k67VfPhKczrzA/CUtf58L6Z++xQeanU2z8abhgE/PPMhEudSZMsJER3wkVbHCy/tmZrJsmLP35H4XuUXos+eW8x+ZHLJg/f6H4E/u8efPmzJ079/u0GnyBWeQs/18yd+68hRT0+aT7ew//g/Dh5x/989/YnyApxuVsjAAAAABJRU5ErkJggg==",
        "name": "projectname3",
        "plannedEndDate": "2012-05-23T00:00:00+01:00",
        "plannedStartDate": "2012-05-23T00:00:00+01:00",
        "projectStatus": {
            "name": "In Progress"
        },
        "realEndDate": "2012-05-23T00:00:00+01:00",
        "realStartDate": "2012-05-23T00:00:00+01:00"
    }
}

当Web服务返回多个元素时,这是我的JSON数据:

{
    "project": [
        {
            "abbreviation": "abd",
            "customer": "customer1",
            "description": "description1",
            "icon": "iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAN4UlEQVR42u2ZeXBUx53Hx8FgSAIWMiB0jO7RLRkwbFxxnC1ntyp/JXbh9TrmirEDOpA4JQQ6kdCBDiQOU65UjNdO2djYGLCzKRJjY841SJoZzaEZaTSjc0b3hST0JCH5u79fa54YCZLUZteurQpTfKq7X/f0+35//et+b4RC8fDz8PPw8/Dz8PMP/ykoKFBkZmY+evLkyR9//PHHr545c2azC6/9BUQ/jd/w4Ycf/uLNN9+M3r179w8AKNzd3b878eXl5QoSoXjnnXd+ZjAYmjo7Oye6uromme7u7m+coKenR+YbF3jcWHt7+2B9fX3r1atXP3777befW7du3aOpqanfjYGysjJFY2Oj4uzZszt6e3sxOjoqGBu/i7sTE8QkJia/EdC/aeRr3D9+9y7Gx8cxPDyM2tpaO821JysrayHP/Z0YuH37tuLcuXO7+vr6vpEN9LZa4DBcQ5vxGjpqrqOz5ga6TIT5Brpd6K27hZGBboyNjU2bdzgcdy5duvS7N954I4Ru8ciWLVu+XQMDAwO8AjvZAEe+v7kG2pyfQLvTG7rdSuj3+MKQ4gdjqr+gJtUPpr2+MKcoUZushP10CkZHhoV4SZIENNeEXq+vvnDhwqFTp05tfPfdd1+gNP3l/5a33nrrudLS0sePHj2qyMvLu9/A+N0J9JmvonE/CUtdBHvWUtgLvGEv9Ye9PHCKEj/Y871gz1wCe/IP0fnbtZAG+yCRgZGREdy5c0fAKUVpOUkrIrW0tAw3NzcPNzU1DTGUtoKGhgaBzWYTWK3WIdpPAovFIqirqxNQeg5TUPo+++yzQ+vXr3/0yJEjD1qBcYwO38bA1++g90IG+r7MRd+1QvTdLEFfVRn6Kg+j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iYGjZISM9ZLZHjLeRYHopIBYCpWdFzO9Ij7P9FIo+M9zly9fZgNxJtoD2j8chyl1DazJT9FGXEkRj6aIR1DEQ9FxQIWu3CD05AWS8AAMFJLoogAMlQRguDQAI4cDIZUFYbQ8GGNHVEQIxo+GTnGM6sdURBDGjwcQfhg7riS8MXrcExKZGCEDd8gAM3RsCQaP8orwalC6lVF60SqyAWNOkPmjXdE+Z5IjFYpHHnmE/8Y7JyUl5blz5z81/fH3x6Qvdv5Y+q9tMdLNpCjp1vYIqXJnuKTeFSpp94RIumSVpE9RSYa9wVJNarBk2qeSzPtVUm1aiFSXHirVZ4RJ1swIyZYZKTVkRUkN2TFSoyCa6tyOIMIkW3aIZM0OluqzA4kAyZLlL9Vl+UrmTF/JlKmUTBlKyUgY0pWSPt1Xqk7zk7T7/aVbe4PunI6NPLlS5fME61bMmTPne4899pj7ggULVq9Zs+bVtS+8sO+lf3k67VfPhKczrzA/CUtf58L6Z++xQeanU2z8abhgE/PPMhEudSZMsJER3wkVbHCy/tmZrJsmLP35H4XuUXos+eW8x+ZHLJg/f6H4E/u8efPmzJ079/u0GnyBWeQs/18yd+68hRT0+aT7ew//g/Dh5x/989/YnyApxuVsjAAAAABJRU5ErkJggg==",
            "name": "projectname1",
            "plannedEndDate": "2012-05-25T00:00:00+01:00",
            "plannedStartDate": "2012-05-23T00:00:00+01:00",
            "projectStatus": {
                "name": "Opened"
            },
            "realEndDate": "2012-05-25T00:00:00+01:00",
            "realStartDate": "2012-05-23T00:00:00+01:00"
        },
        {
            "abbreviation": "bd",
            "customer": "customer1",
            "description": "description2",
            "icon": "iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAN4UlEQVR42u2ZeXBUx53Hx8FgSAIWMiB0jO7RLRkwbFxxnC1ntyp/JXbh9TrmirEDOpA4JQQ6kdCBDiQOU65UjNdO2djYGLCzKRJjY841SJoZzaEZaTSjc0b3hST0JCH5u79fa54YCZLUZteurQpTfKq7X/f0+35//et+b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IkW3aIZM0OluqzA4kAyZLlL9Vl+UrmTF/JlKmUTBlKyUgY0pWSPt1Xqk7zk7T7/aVbe4PunI6NPLlS5fME61bMmTPne4899pj7ggULVq9Zs+bVtS+8sO+lf3k67VfPhKczrzA/CUtf58L6Z++xQeanU2z8abhgE/PPMhEudSZMsJER3wkVbHCy/tmZrJsmLP35H4XuUXos+eW8x+ZHLJg/f6H4E/u8efPmzJ079/u0GnyBWeQs/18yd+68hRT0+aT7ew//g/Dh5x/989/YnyApxuVsjAAAAABJRU5ErkJggg==",
            "name": "projectname2",
            "plannedEndDate": "2012-05-23T00:00:00+01:00",
            "plannedStartDate": "2012-05-23T00:00:00+01:00",
            "projectStatus": {
                "name": "Closed"
            },
            "realEndDate": "2012-05-23T00:00:00+01:00",
            "realStartDate": "2012-05-23T00:00:00+01:00"
        },
        {
            "abbreviation": "abc",
            "customer": "customer1",
            "description": "description3",
            "icon": "iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAN4UlEQVR42u2ZeXBUx53Hx8FgSAIWMiB0jO7RLRkwbFxxnC1ntyp/JXbh9TrmirEDOpA4JQQ6kdCBDiQOU65UjNdO2djYGLCzKRJjY841SJoZzaEZaTSjc0b3hST0JCH5u79fa54YCZLUZteurQpTfKq7X/f0+35//et+b4RC8fDz8PPw8/Dz8PMP/ykoKFBkZmY+evLkyR9//PHHr545c2azC6/9BUQ/jd/w4Ycf/uLNN9+M3r179w8AKNzd3b878eXl5QoSoXjnnXd+ZjAYmjo7Oye6uromme7u7m+coKenR+YbF3jcWHt7+2B9fX3r1atXP3777befW7du3aOpqanfjYGysjJFY2Oj4uzZszt6e3sxOjoqGBu/i7sTE8QkJia/EdC/aeRr3D9+9y7Gx8cxPDyM2tpaO821JysrayHP/Z0YuH37tuLcuXO7+vr6vpEN9LZa4DBcQ5vxGjpqrqOz5ga6TIT5Brpd6K27hZGBboyNjU2bdzgcdy5duvS7N954I4Ru8ciWLVu+XQMDAwO8AjvZAEe+v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J16sOrj0fgO1t87QQ+xpEruGIvwULDtXoX73CopwDEU4Cs37wtGaHgpHpgrt2UEkOADdtLw9+X7oLfBDP0VqgG5yu1iJ2yVKDJb6YPAw442hMq8pyj2J5YQHBo8wy3BbsBQDRH/5MvQRvWUe6C7zRNdhL3SWeqOjhFaM5rQd8hq6nrfs2Ru5HorpTUwGktiA8dJJGPf/CJZdq1G/5ynK55VoTI1BC71d2jPC0J4VQqKDSXQgiQ5AHy3pwCF/EuyPwRJ/DJX6Y/iwP+6U+WOknDjiD4k56kf4QjrG+BDeGDnmhZHjywkP3Dm+DMOCpRg8thS3iYGjZISM9ZLZHjLeRYHopIBYCpWdFzO9Ij7P9FIo+M9zly9fZgNxJtoD2j8chyl1DazJT9FGXEkRj6aIR1DEQ9FxQIWu3CD05AWS8AAMFJLoogAMlQRguDQAI4cDIZUFYbQ8GGNHVEQIxo+GTnGM6sdURBDGjwcQfhg7riS8MXrcExKZGCEDd8gAM3RsCQaP8orwalC6lVF60SqyAWNOkPmjXdE+Z5IjFYpHHnmE/8Y7JyUl5blz5z81/fH3x6Qvdv5Y+q9tMdLNpCjp1vYIqXJnuKTeFSpp94RIumSVpE9RSYa9wVJNarBk2qeSzPtVUm1aiFSXHirVZ4RJ1swIyZYZKTVkRUkN2TFSoyCa6tyOIMIkW3aIZM0OluqzA4kAyZLlL9Vl+UrmTF/JlKmUTBlKyUgY0pWSPt1Xqk7zk7T7/aVbe4PunI6NPLlS5fME61bMmTPne4899pj7ggULVq9Zs+bVtS+8sO+lf3k67VfPhKczrzA/CUtf58L6Z++xQeanU2z8abhgE/PPMhEudSZMsJER3wkVbHCy/tmZrJsmLP35H4XuUXos+eW8x+ZHLJg/f6H4E/u8efPmzJ079/u0GnyBWeQs/18yd+68hRT0+aT7ew//g/Dh5x/989/YnyApxuVsjAAAAABJRU5ErkJggg==",
            "name": "projectname3",
            "plannedEndDate": "2012-05-23T00:00:00+01:00",
            "plannedStartDate": "2012-05-23T00:00:00+01:00",
            "projectStatus": {
                "name": "In Progress"
            },
            "realEndDate": "2012-05-23T00:00:00+01:00",
            "realStartDate": "2012-05-23T00:00:00+01:00"
        }
    ]
}

在android端,我反序列化JSON响应,如下所示:

Gson gson = new Gson();
final ProjectContainer container = gson.fromJson(resultat, ProjectContainer.class);
final ListView lv = (ListView) findViewById(R.id.list);
adaptateur = new ProjectAdapter(ProjectActivity.this, R.layout.ligne_project, container);
lv.setAdapter(adaptateur);

这是我的ProjectContainer类:

  public class ProjectContainer {
        @SerializedName("project")
        List<Project> projects ;

        public List<Project> getProjects() {
            return projects;
        }    
        public void setProjects(List<Project> projects) {
            this.projects = projects;
        }
    }

非常感谢您为解决此问题所提供的帮助。提前致谢


问题答案:

您的问题结果对我来说真的很奇怪。似乎Jersey的单元素数组的JSON序列化肯定存在一些问题…如果您使用Google“ JerseyJSON单元素的数组 ”,则会发现相同的问题,例如
此处
在这里 。我对泽西岛不太了解,所以我无法为您提供帮助…

也就是说,我可以建议一种解决方法,在Gson中使用手动解析,以使您的解析适应2种不同的响应(对象或数组)。您可以执行以下操作:

//manually parsing until get the "project" element...
JsonParser parser = new JsonParser();
JsonObject rootObejct = parser.parse(yourJsonString).getAsJsonObject();
JsonElement projectElement = rootObejct.get("project");

Gson gson = new Gson();
List<Project> projectList = new ArrayList<>();

//Check if "project" element is an array or an object and parse accordingly...
if (projectElement.isJsonObject()) {
    //The returned list has only 1 element
    Project project = gson.fromJson(projectElement, Project.class);
    projectList.add(project);
}
else if (projectElement.isJsonArray()) {
    //The returned list has >1 elements
    Type projectListType = new TypeToken<List<Project>>() {}.getType();
    projectList = gson.fromJson(projectElement, projectListType);
}

//Now you have a List<Project> projectList with one or many Project elements, 
//depending on the response...

请注意,您不需要上课ProjectContainer

尽管显然最好的办法是解决序列化问题,但类似的事情应该对您有用!



 类似资料:
  • 我的Retrofit2调用出现以下异常: 学分类别:

  • 我将请求映射到类,如下所示: 有人能解释为什么我在请求中的数组没有与类A中的数组映射吗?

  • 我试图使用gson解析下面的json字符串,并且我得到了这个异常。 异常很明显,它期待一个对象(可能是Datapoint),但它遇到了一个数组。我确信是我的模型类导致了这个问题,但是我不明白我的模型类应该是什么样子才能解析json而不会失败。

  • 问题内容: JSON对象示例如下所示: 假设通过链接www.domain.com访问上述对象,并​​且我具有以下用于表示数据的类 并且地址类如下: 当我尝试跑步 我收到以下错误: 预期为BEGIN_ARRAY,但在上述代码行中为字符串。我不确定我设置班级的方式是否有问题。注意:我正在使用一个数组(LocationData []数据),因为该服务返回了多个位置,尽管我刚刚在上面显示的示例中包括了一个

  • 问题内容: 我正在尝试将内容反序列化为自定义类型。 这段代码 引发跟随异常 为什么Gson无法将我的JSON文本正确转换为我的POJO类型? 问题答案: 作为异常消息状态 反序列化时,Gson期望使用JSON对象,但发现了一个JSON数组。由于无法从一种转换为另一种,因此引发了此异常。 此处描述JSON格式。简而言之,它定义了以下类型:对象,数组,字符串,数字和null,以及布尔值和。 在Gson

  • 问题内容: 我在尝试将JSON解组到对象中时遇到GSON错误。错误( 应为BEGIN_OBJECT,但在第3行第22列处为STRING )指向下面输入的第3行。 我是否相对于Bean正确映射了JSON? 我输入的JSON看起来是这样的: 问题答案: 不,您没有正确映射它,因为您的json对象不是,它包含。 你可以创建一个类只是为了封装你,但它是清洁反序列化容器的使用 然后使用解析有趣的内容 并且我