The background interface sends data to the Android client through a json object, and uses json to parse the received data.
packages that need to be imported
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
Send data
in a class on the server side, generate a json string
//声明一个Hash对象并添加数据
Map params = new HashMap();
params.put("username", username);
params.put("user_json", user);
//声明JSONArray对象并输入JSON字符串
JSONArray array = JSONArray.fromObject(params);
put.println(array.toString());
List<> list = new ArrayList<>();
list.add("姓名",1);
list.add("年龄",2);
JSONArray jsonarray = JSONArray.fromObject(list);
Analytical data
//根据接收到的JSON字符串来解析字符串中所包含的数据和数据对象
//接收到的JSON字符串
String result = "[{\"user_desc\": \"desc\", \"user_json\": {\"user_name\": \"name\", \"user_age\": \"age\"}}]";
//String字符串生成JSON对象
JSONArray resultArray = new JSONArray(result);
JSONObject resultObj = resultArray.optJSONObject(0);
//获取数据对象
JSONObject user = resultObj.getJSONObject("user_json");
String name= user.getString("user_name");