com.alibaba.fastjson.JSONException: not match : - =异常

前端之家收集整理的这篇文章主要介绍了com.alibaba.fastjson.JSONException: not match : - =异常前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在使用fastjson来将json数据转换成model时出现如下异常:

wKiom1O7mBiD_iRjAAU-358vdLI086.jpg

publicclassTestDemo{

	publicstaticvoidmain(String[]args)throwsIOException{
		StringresponseData=
			"{\"code\":0,\"errorDescription\":\"操作成功\","+
			"\"dataObject\":{\"imgUrl\":\"https://mobilecodec.alipay.com/show.htm"+
			"?code=pvv4z94z8tnazwek0c&picSize=M\",\"expireSecond\":1800}}";
		RestModelrestModel=(RestModel)JsonUtil.jsonToObject(responseData,RestModel.class);
		Stringstr=restModel.getDataObject().toString();
		ZpSpreadInfoByAlipayRspzpSpreadInfoByAlipayRsp=(ZpSpreadInfoByAlipayRsp)JsonUtil
				.jsonToObjectByRest(str,ZpSpreadInfoByAlipayRsp.class);
		StringimgUrl=zpSpreadInfoByAlipayRsp.getImgUrl();
		System.out.println(imgUrl);
	}
}


publicclassJsonUtil{
	publicstaticObjectjsonToObject(Stringjson,Classcls)
		throwsJsonGenerationException,JsonMappingException,IOException{
		Objectobj=null;
		ObjectMappermapper=newObjectMapper();
		mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES,true);
		obj=mapper.readValue(json,cls);
		returnobj;
	}
}

猜你在找的Json相关文章