我是靠谱客的博主 大意毛豆,这篇文章主要介绍json转List对象,com.alibaba.fastjson.JSONException: syntax error, pos 1, json : http:/,现在分享给大家,希望可以做个参考。
报错:com.alibaba.fastjson.JSONException: syntax error, pos 1, json : http:/
原因是因为接口返回的有空值,最简单的办法就是创建一个实体类接收
String json = HttpUtils.get("http://ip/blank",null);
List<Blankstock> list = JSONObject.parseArray(json,Blankstock.class);
public static String get(String url, Map<String, String> paramsMap) {
CloseableHttpClient client = HttpClients.createDefault();
String responseText = "";
CloseableHttpResponse response = null;
try {
String getUrl = url+"?";
if (paramsMap != null) {
for (Map.Entry<String, String> param : paramsMap.entrySet()) {
getUrl += param.getKey() + "=" + URLEncoder.encode(param.getValue(), ENCODING)+"&";
}
}
HttpGet method = new HttpGet(getUrl);
response = client.execute(method);
HttpEntity entity = response.getEntity();
if (entity != null) {
responseText = EntityUtils.toString(entity);
}
} catch (Exception e) {
log.error("http request failed",e);
} finally {
try {
response.close();
} catch (Exception e) {
log.error("",e);
}
}
return responseText;
}
//获取了单个的对象,可以对这个进行操作
for(Blankstock Blankstock:list){
//插入数据库的操作
this.blankstockMapper.insert(Blankstock);
}
获取http接口数据,然后转化为类list
最后
以上就是大意毛豆最近收集整理的关于json转List对象,com.alibaba.fastjson.JSONException: syntax error, pos 1, json : http:/的全部内容,更多相关json转List对象,com.alibaba.fastjson.JSONException:内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复