com.alibaba.fastjson.JSONException: not match : - =异常
程序员文章站
2022-07-14 22:54:01
...
在使用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;
}
}
转载于:https://blog.51cto.com/xiaosuisky/1435866