在使用fastjson来将json数据转换成model时出现如下异常:
public class TestDemo { public static void main(String[] args) throws IOException { String responseData = "{\"code\":0,\"errorDescription\":\"操作成功\"," + "\"dataObject\":{\"imgUrl\":\"https://mobilecodec.alipay.com/show.htm" + "?code=pvv4z94z8tnazwek0c&picSize=M\",\"expireSecond\":1800}}"; RestModel restModel = (RestModel) JsonUtil.jsonToObject(responseData,RestModel.class); String str = restModel.getDataObject().toString(); ZpSpreadInfoByAlipayRsp zpSpreadInfoByAlipayRsp = (ZpSpreadInfoByAlipayRsp) JsonUtil .jsonToObjectByRest(str,ZpSpreadInfoByAlipayRsp.class); String imgUrl = zpSpreadInfoByAlipayRsp.getImgUrl(); System.out.println(imgUrl); } } public class JsonUtil { public static Object jsonToObject(String json, Class cls) throws JsonGenerationException, JsonMappingException, IOException { Object obj = null; ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); obj = mapper.readValue(json, cls); return obj; } }