怎么用JAVA从一个url里把所有的JSON objects全部读取出来,并且存到指定的数据结构里?url就是https://candidate.hubteam.com/candidateTest/v3/problem/dataset?userKey=1cae96d3904b260d06d0daa7387c
解决方案 »
- java?curl?http请求时间细节,怎么实现?
- 如何设计动态表单的数据库表
- 如何用openJPA处理并发事件
- spring包的问题
- jms发送消息如何判断是否发送成功
- 表单中有两个提交按钮,比如一个是“增加”,另一个是“修改”,提交给一个Struts的action,如何能在action类中判断出用户到底提交了哪个
- 配置Hibernate后TOMCAT启动不了!
- ejb在编译后还和里面的import的路径有关吗?出错了
- 一个挺简单的问题?望指教!!
- 一个菜鸟级的问题:Java中的组件是什么概念,于其它有什么不同
- 基于Druid连接池的JdbcTemplate.queryForObject 一直返回空对象
- help ! postman接口响应xml报文乱码怎么解决?
https://blog.csdn.net/qq_42815754/article/details/83448029
你的url 虽然是这个,但是里面就一个userKey参数.从而分析,很有可能 还有其他的json对象是通过header的方式或者其他方式传入的.所以,但看一个url 是根本不需要你说的那样的.你应该把接口定义贴出来.才能更好的分析此问题.
2)把字符串解释为对象,这个可以下载一个json包就行了,比如:google的json解释包。
import java.net.URI;
import java.net.URISyntaxException;import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
public class HttpsRequestClient {
private Log logger = LogFactory.getLog(this.getClass());
private String s1 = "Http请求服务工具";
private String httpGet(URI uri) {
String strData = null;
CloseableHttpClient httpclient =null;
CloseableHttpResponse response =null;
try {
if(logger.isDebugEnabled()) {
logger.debug(s1+","+uri.toString());
}
httpclient = HttpsNoSslClient.getClient();
//HttpPut httpput = new HttpPut(url);
//HttpDelete httpDelete = new HttpDelete(url);
//HttpPost httppost = new HttpPost(url);
HttpGet httpget = new HttpGet(uri);
response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
String httpData = EntityUtils.toString(entity, "UTF-8");
strData = httpData;
if(logger.isDebugEnabled()) {
logger.debug(s1+","+httpData);
}
response.close();
httpclient.close();
} catch (Exception e) {
throw new RuntimeException(s1+",调用异常,可能是网络问题", e);
} finally {
try {
if(response != null) {response.close(); }
response = null;
if(httpclient != null) {httpclient.close(); }
httpclient = null;
} catch (IOException e) {
e.printStackTrace();
}
}
return strData;
}
public static void main(String[] args){
}}
//JSON处理数据:
Map<String,Object> msgdata = com.alibaba.fastjson.JSON.parseObject(httpData);