Home > Mobile >  The server response returned multiple data, the client how to receive?
The server response returned multiple data, the client how to receive?

Time:10-05

服务器端返回了三条数据,客户端通过解析json只能获得一条数据,然后通过浏览器访问就能看到三条,以下是客户端,服务器端的代码,求大佬指教

CodePudding user response:

The server-side code
Protected void doGet (it request, HttpServletResponse response)
Throws ServletException, IOException {
The response. SetContentType (" application/json; charset=utf-8");
Request. SetCharacterEncoding (" utf-8 ");
The response. SetCharacterEncoding (" utf-8 ");
PrintWriter out=response.getWriter();

//get the request of the user name and password

String username=request. The getParameter (" username "). The trim ();
List Lst2=UserDAO. GetOracleFindAll (username);
The User the User;
JSONObject a=new JSONObject ();


for(int i=0; iUser=lst2. Get (I);
String classname=user. Getclassname ();
String coursename=user. Getcoursename ();
String num=user. Getnum ();
String requested=user. Getrequested ();
Amy polumbo ut (" username ", username);
Amy polumbo ut (" classname ", the classname);
Amy polumbo ut (" coursename ", coursename);
Amy polumbo ut (" num ", num);
Amy polumbo ut (" requested ", requested);
Out=response. GetWriter ();
Out.println (a);
}

}

CodePudding user response:

The android client code
RequestQueue mQueue=Volley. NewRequestQueue (MainActivity. This);
JsonObjectRequest JsonObjectRequest=new JsonObjectRequest (jsonurl, null, new Response. Listener () {
@ Override
Public void onResponse (JSONObject response) {
Try {

String classname.
String coursename;

The classname=new String (new String (response. Get String (" classname ")));
Coursename=new String (new String (response. Get String (" coursename ")));
The classname=new a classname (classname, coursename);
System. The out. Println (coursename);

ClassnameList. Add (a);

Adapter Adapter=new Adapter (classnameList);

RecyclerView. SetAdapter (adapter);
} the catch (JSONException e) {

The e (" json error ", um participant etMessage ());
}
}
},

CodePudding user response:

Have to solve the problem!!!!!!!!!!!!!!!!!!!!!!!

CodePudding user response:

Figure all paste QAQ.
But I want to know how to receive

CodePudding user response:

I just want to have a look at figure,,,,
  • Related