java.lang.IllegalStateException:预期BEGIN_ARRAY但在第1行第4130行是BEGIN_OBJECT

时间:2017-11-14 21:27:05

标签: json gson

我有以下json :(我在名为locations的对象中看到一个地图) 我做了一个gson调用,将它转换为带有地图的对象。 也许我看到json错了。 我做错了什么?

{
  "locations": {
    "0": {
      "locationNo": "10014",
      "inventoryLocationNo": "10014"
    },
    "1": {
      "locationNo": "10022",
      "inventoryLocationNo": "10022"
    },
    "2": {
      "locationNo": "10030",
      "inventoryLocationNo": "10030"
    },
 },
  "errors": {}
}

这是我的代码

我拨打电话时收到异常:

BATOLocationIDAPIResponse responseObject = gson.fromJson(container.body, BATOLocationIDAPIResponse.class);

这是我的代码

/**
 * POJO that represents the response wrapper for a Location API call.
 *
 */
public class BATOLocationIDAPIResponse {
    private BATOLocationContainer locations;
    private List<String> errors;
    }
    public List<String> getErrors() {
        return errors;
    }
    public class BATOLocationContainer {
        private Map<String, BATOAPILocation> locations;
     }
}
// Location object
    public class BATOAPILocation {
        public String locationNo;
        public String inventoryLocationNo;
     }

1 个答案:

答案 0 :(得分:0)

您有private List<String> errors;,但您的JSON显示"errors": {}这应该是"errors": []

这样的数组