In order to parse the content from the .json file I use Jackson 2.2.x and prepared the following method:public static List<Location> getLocations(InputStream inputStream) { ObjectMapper objectMapper = new ObjectMapper(); try { TypeFactory typeFactory = objectMapper.getTypeFactory(); CollectionType collectionType = typeFactory.constructCollectionType( List.class, Location.class); return objectMapper.readValue(inputStream, collectionType); } catch (IOException e) { e.printStackTrace(); } return null;}只要我省略center属性,就可以解析所有内容.但是,当我尝试解析地理坐标时,出现以下错误消息:As long as I leave out the center property all content can be parsed. However, when I try to parse the geo-coordinates I end up with the following error message: com.fasterxml.jackson.databind.JsonMappingException:无法反序列化的实例 com.example.GeoPoint不在START_ARRAY令牌中,位于[来源:android.content.res.AssetManager$AssetInputStream@416a5850;行:5,列:25] (通过参考链:com.example.Location ["center"]) com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of com.example.GeoPoint out of START_ARRAY token at [Source: android.content.res.AssetManager$AssetInputStream@416a5850; line: 5, column: 25] (through reference chain: com.example.Location["center"])推荐答案您的JSON字符串格式不正确:center的类型是无效对象的数组.在longitude和latitude周围的JSON字符串中将[和]替换为{和},这样它们将成为对象:Your JSON string is malformed: the type of center is an array of invalid objects. Replace [ and ] with { and } in the JSON string around longitude and latitude so they will be objects:[ { "name" : "New York", "number" : "732921", "center" : { "latitude" : 38.895111, "longitude" : -77.036667 } }, { "name" : "San Francisco", "number" : "298732", "center" : { "latitude" : 37.783333, "longitude" : -122.416667 } }] 这篇关于用Jackson&从json文件解析内容的问题消息-JsonMappingException-无法从START_ARRAY令牌中反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-20 15:45