The data that the project needs to post from PHP to Servlet,post is JSON, so I wrote a small example to test it.
The source code is:
Import java.util.ArrayList;
Import Net.sf.json.JSONArray;
Import Net.sf.json.JSONObject;
public class Jsontest {public
static void Main (string[] args) {
String jsonmessage= "{\" key\ ": \" E5f83436f695a3a316183f4e82702d36ca034ce4\ ", \" category\ ": \" brand\ ", \" ids\ ": [32,45,67,94,43]}";
Jsonobject jsonobject = Jsonobject.fromobject (jsonmessage);
String category = jsonobject.getstring ("category");
Jsonarray array = Jsonobject.getjsonarray ("IDs");
arraylist<integer> ArrayList = new arraylist<integer> ();
for (int i = 0; i < array.size (); i++) {
Arraylist.add (Array.getint (i));
}
SYSTEM.OUT.PRINTLN (category);
SYSTEM.OUT.PRINTLN (array);
System.out.println (arrayList);
}
Output results
Brand
[32,45,67,94,43]
[32, 45, 67, 94, 43]
Note: Java parsing JSON requires importing the following packages