用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());
}