HTTP请求数据返回解析Josn org.codehaus.jackson.map.JsonMappingException的解决方法

来源:互联网 发布:linux权限管理root 编辑:程序博客网 时间:2024/05/01 08:02

用http向服务器发起请求,解析返回数据出现Josn org.codehaus.jackson.map.JsonMappingException



问题代码:

    public void onSuccess(ResponseInfo<String> responseInfo) {
                ObjectResponse<CommCarCurrentLoInfoEntity> response = ResponseParser.toObjectResponse
                        .toListResponse(responseInfo.result,
                                CommCarCurrentLoInfoEntity.class);
                if (response != null) {
                    CommCarCurrentLoInfoEntity data = response.getData();
                    
                        lastPoint = new LatLng(data.getLoLtt()
                                .doubleValue(), data.getLoLgt()
                                .doubleValue());

                                     }

返回数据:


抛异常的原因:

返回的result 里头的data是个list,即使你知道只返回一个实例。所以不能用ResponseParser.toObjectResponse来解析而应该用ResponseParser.toListResponse来解析。

正确代码:

    public void onSuccess(ResponseInfo<String> responseInfo) {
                ListResponse<CommCarCurrentLoInfoEntity> response = ResponseParser
                        .toListResponse(responseInfo.result,
                                CommCarCurrentLoInfoEntity.class);
                if (response != null) {
                    List<CommCarCurrentLoInfoEntity> data = response.getData();
                    if (data.size() >0) {
                        lastPoint = new LatLng(data.get(0).getLoLtt()
                                .doubleValue(), data.get(0).getLoLgt()
                                .doubleValue());

                     }







0 0
原创粉丝点击