First to the company internship, you need to get the JSON data returned by the third-party interface via HTTP POST and parse the JSON array to get the value
@RequestMapping ("/getproductname")
@ResponseBody
PublicArrayList Getproductname (HttpServletRequest request)throwsException {
HttpPost HttpPost =NewHttpPost ("");
Closeablehttpclient client = httpclients.Createdefault();
String respcontent =NULL;
Jsonobject Jsonparam =NewJsonobject ();
stringentity entity =NewStringentity (Jsonparam.tostring (),"Utf-8");//solve Chinese garbled problem
Entity.setcontentencoding ("UTF-8");
Entity.setcontenttype ("Application/json");
Httppost.setentity (entity);
System. out. println ();
ArrayList productlist =NewArrayList ();
Try{
HttpResponse resp = Client.execute (HttpPost);
if(Resp.getstatusline (). Getstatuscode () = = 200) {
Httpentity he = resp.getentity ();
Respcontent = Entityutils.toString(He,"UTF-8");
System. out. println ("This section outputs third-party access data----------------> "+respcontent);
Jsonobject jsonobject= JSON.parseobject(respcontent);
String Jsonstr =jsonobject.getstring (" properties that need to be acquired in JSON ");//removedJSONOne of the properties in the array
System. out. println ("This output returns the product name"+JSONSTR);
Jsonarray Jsonarray = Jsonobject.getjsonarray (" properties that need to be acquired in JSON ");
for(inti = 0;i<jsonarray.size (); i++) {
//Object list = Jsonarray.get (i);
//system.out.println (list);
}
Jsonobject Jo = Jsonobject.parseobject(respcontent);
System. out. println ("=============="+JO);
Net.sf.json.JSONObject jsonobj = Net.sf.json.JSONObject.Fromobject(Jo);
Net.sf.json.JSONArray jsonArray1 = Jsonobj.getjsonarray ("Properties that need to be acquired in JSON");
for(intI=0;i<jsonarray1.size (); i++)
{
String productName = (string) jsonarray1.getjsonobject (i). Get ("One of the properties in a JSON array");
System. out. println (ProductName);
Productlist.add (ProductName);
}
}}Catch(Exception e) {
System. out. println ("An exception occurred to the docking third-party interface");
}
returnProductList;
}
HttpClient obtaining third-party interface data and parsing get JSON