有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用截取来获取列表中多个ID的响应

我有一个ID列表,我想获取列表中每个ID的数据。在循环列表时,是否可以使用volley或任何其他网络库而不必调用请求来节省执行时间


共 (2) 个答案

  1. # 1 楼答案

    以下是我迄今为止所做的工作。要发送每个ID的多个网络请求,需要一个新的RequestQueue构造函数(用于volley)。 `RequestQueue mrrequestqueue=Volley。newRequestQueue(mContext)

            // Instantiate the cache
            Cache cache = new DiskBasedCache(mContext.getCacheDir(), 1024 * 1024); // 1MB cap
    
            // Set up the network to use HttpURLConnection as the HTTP client.
            BasicNetwork network = new BasicNetwork(new HurlStack());
    
            mRequestQueue = new RequestQueue(cache, network, 29);
    //The Integer 29 indicate the number of requests, 
    //hence, the number of concurrent threads volley will run on its Looper and 
    //Handler.
    
            // Start the queue
            mRequestQueue.start();
    
           //Make request here
    

    我希望这对任何人都有帮助

  2. # 2 楼答案

    是的,您可以,如果响应包含ID,则只需要一个请求,然后您可以在JSON解析期间获取列表ID