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);
} 展开
使用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);
} 展开
展开全部
出现这个异常的原因是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());
}
}
将你的数据和代码放到程序中是可以运行的,应该还是数据的问题
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}这是原来的数据,我把他切分了,不可能有空的地方的吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询