Java 来自同一活动中两个JSON URL的Android/JSON返回对象

Java 来自同一活动中两个JSON URL的Android/JSON返回对象,java,android,json,url,android-asynctask,Java,Android,Json,Url,Android Asynctask,这是代码: @Override protected DVLAInformation doInBackground(String... params) { try { Intent intent = getIntent(); String dvlaNumFin = intent.getStringExtra("dvlaNumber"); final URL u

这是代码:

@Override
        protected DVLAInformation doInBackground(String... params) {
            try {

                Intent intent = getIntent();
                String dvlaNumFin = intent.getStringExtra("dvlaNumber");

                final URL url = new URL("https://dvlasearch.appspot.com/DvlaSearch?licencePlate=" + dvlaNumFin + "&apikey=");
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();


                connection.setRequestMethod("GET");
                connection.setRequestProperty("USER-AGENT", "Mozilla/5.0");
                connection.setRequestProperty("ACCEPT-LANGUAGE", "en-US,en;0.5");

                BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                String line;
                StringBuilder responseOutput = new StringBuilder();
                while ((line = br.readLine()) != null) {
                    responseOutput.append(line);
                }
                br.close();

                DVLAInformation obj = new DVLAInformation(url.toString());
                obj.readAndParseJSON(responseOutput.toString());



                return obj;


            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;


        }
我的问题是如何在同一活动中从两个JSON URL返回对象

例如,我将有两个URL

final URL url = new URL("https://dvlasearch.appspot.com/DvlaSearch?licencePlate=" + dvlaNumFin + "&apikey=DvlaSearchDemoAccount");
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();

final URL url2 = new URL("https://dvlasearch.appspot.com/MotHistory?licencePlate=mt09nks&apikey=DvlaSearchDemoAccount");
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
我不知道如何返回这样的内容:

    DVLAInformation obj = new DVLAInformation(url.toString());
                    obj.readAndParseJSON(responseOutput.toString());
    DVLAInformation obj2 = new DVLAInformation(url2.toString());
                    obj2.readAndParseJSON(responseOutput.toString());

return obj, obj2
对不起,我的解释,我知道方法是不正确的,我只是试图解释我想做什么

找到了这个,但不了解如何应用它

请查看。如果你需要指导,你可能会发现这很有用


作为替代方案,您可以使用OkHttp并链接HTTP请求。

还有其他方法吗?例如创建两个AsyncTask或两个doInBackground?是的,但不要使用AsyncTasks,它们仅用于短期操作,请查看类这是我需要的,作为短期操作查找教程(添加到帖子中),但不了解如何应用它。