首页 > 解决方案 > 如何在没有使用 Volley 的节点 js 的 Android 中合并 JSON 的情况下获得多 Json 响应?

问题描述

我正在使用带有 Nodejs 的 Android Studio。要获取数据,我想使用'volley'从nodejs服务器获取Json在服务器(Nodejs,Express)交付Tow JSon

                res.write(JSON.stringify(results));
                res.write(JSON.stringify(hot));

我想将这些 Json 从服务器获取到 Android 但失败了……我只能得到一个首先交付的 JSON,这个

     res.write(JSON.stringify(results));

我怎样才能得到两个 JSON ?不合并 JSON

public void onButton1Clicked(View v){

    String url=editText.getText().toString();
    StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            try {
                println(response);
                JSONArray jarray= new JSONArray(response);

                for(int i=0;i<jarray.length();i++)
                {
                    JSONObject Jobs=jarray.getJSONObject(i);
                    String title=Jobs.getString("title");
                    String content=Jobs.getString("content");

                    println(" title : " + title);
                    println(" content : " + content);

                }

            } catch (Exception e) {
                println("에러남!");
                e.printStackTrace();
            }
        }
    },new Response.ErrorListener(){
                @Override
                public void onErrorResponse(VolleyError error) {
                    println("error!@@@");
                    error.printStackTrace();
                }
            }

    ){
        @Override
        protected Map<String, String> getParams(){
            Map<String, String> params = new HashMap<>();
            return params;
        }
    };
    request.setShouldCache(false);
    Volley.newRequestQueue(this).add(request);
    println("웹 서버에 요청함 : "+url);
}

标签: androidjsonnode.jsexpressandroid-volley

解决方案


推荐阅读