json转换为javabean报错。A JSONObject text must begin with '{' at character 0 of

这是str输出{"address":"33","conTel":"","desc":"","email":"","eptCarports":498,"freeTime":... 这是str输出{"address":"33","conTel":"","desc":"","email":"","eptCarports":498,"freeTime":0,"inEntranceNum":0,"isCharge":1,"latitude":"23.04715","longitude":"113.102868","outEntraceNum":0,"parkCode":"2KPI5T73","parkName":"对外调试停车场","totalCarports":999}

使用str数据,把json转换为javabean去存到数据库中报错
for (String str : proStr) {
System.out.println(str);
ParkInfo park = (ParkInfo) JSONObject.toBean(JSONObject.fromObject(str), ParkInfo.class);
System.out.println(park);
ParkInfo PA = this.parkepository.save(park);

}
展开
 我来答
卡洛琳1016
2019-07-16 · TA获得超过228个赞
知道小有建树答主
回答量:208
采纳率:78%
帮助的人:54.5万
展开全部
出现这个异常的原因是json串格式不正常,没有"{"开始或没有"}"结尾
将你的数据和代码放到程序中是可以运行的,应该还是数据的问题
import net.sf.json.JSONObject;

public class ParkInfoService {

public static void main(String[] args) {
String str = "{\"address\":\"33\",\"conTel\":\"\",\"desc\":\"\",\"email\":\"\",\"eptCarports\":498,\"freeTime\":0,\"inEntranceNum\":0,\"isCharge\":1,\"latitude\":\"23.04715\",\"longitude\":\"113.102868\",\"outEntraceNum\":0,\"parkCode\":\"2KPI5T73\",\"parkName\":\"对外调试停车场\",\"totalCarports\":999}";
System.out.println(str);
ParkInfo park = (ParkInfo) JSONObject.toBean(JSONObject.fromObject(str), ParkInfo.class);
System.out.println(park.toString());
}

}
更多追问追答
追问
{"data":{"address":"33","conTel":"","desc":"","email":"","eptCarports":498,"freeTime":0,"inEntranceNum":0,"isCharge":1,"latitude":"23.04715","longitude":"113.102868","outEntraceNum":0,"parkCode":"2KPI5T73","parkName":"对外调试停车场","totalCarports":999},"message":"业务成功","resultCode":0,"status":1}
这是完整的数据
匿名用户
2019-07-16
展开全部
是不是str前后有多余的空格之类的,改成这个试试JSONObject.fromObject(str.trim())
追问
{"data":{"address":"33","conTel":"","desc":"","email":"","eptCarports":498,"freeTime":0,"inEntranceNum":0,"isCharge":1,"latitude":"23.04715","longitude":"113.102868","outEntraceNum":0,"parkCode":"2KPI5T73","parkName":"对外调试停车场","totalCarports":999},"message":"业务成功","resultCode":0,"status":1}这是原来的数据,我把他切分了,不可能有空的地方的吧
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式