怎么用JAVA从一个url里把所有的JSON objects全部读取出来,并且存到指定的数据结构里?url就是https://candidate.hubteam.com/candidateTest/v3/problem/dataset?userKey=1cae96d3904b260d06d0daa7387c

解决方案 »

  1.   

    参考下其他人的
    https://blog.csdn.net/qq_42815754/article/details/83448029
      

  2.   


    你的url 虽然是这个,但是里面就一个userKey参数.从而分析,很有可能 还有其他的json对象是通过header的方式或者其他方式传入的.所以,但看一个url 是根本不需要你说的那样的.你应该把接口定义贴出来.才能更好的分析此问题.
      

  3.   

    1)取到json字符串,怎么关键看你是get方式或post方式传递。
    2)把字符串解释为对象,这个可以下载一个json包就行了,比如:google的json解释包。
      

  4.   

    先取出来,再处理:import java.io.IOException;
    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);
      

  5.   

    既然是请求,肯定是有接口的,如果是框架的话,直接用变量接收就好,如果不是,request中取不就好了么,为什么需要人工解析
      

  6.   

    没明白这么大段代码在干嘛?请问JSONObject ob = JSONObject.fromObject(new String(result)) 报错怎么办?.fromObject函数不能用了怎么办