tags: Java foundation java
JSONArray data = JSONArray.parseArray(reqMap.get("userListDto").toString());
JSONObject jsonObj = JSONObject.fromObject(resultMap.get("data"));
JSONArray certArray = JSONArray.fromObject(jsonObj.get("userListDto"));
String jsonentity = json.tojsonstring ("Data needed");
JSONObject jsonObject = JSONObject.parseObject(jsonEntity);
JSONArray jsonArray = jsonObject.getJSONArray("userListDto");
The first object parameter
{"userList":[{
"name": "zhangsan",
"sex": 1,
"age":10,
"level": 1
},{
"name": "lisi",
"sex": 1,
"age":13,
"level": 4
},{
"name": "wangwu",
"sex": 1,
"age":12,
"level": 3
}
]}
Use Fastjson's jar package
<dependency>
<groupld>com.alibaba</groupld>
<artifactld>fastjson</artifactld>
</dependency>
import com.alibaba.fastjson.JSONObject;
JSONObject jsonObj = JSONObject.parseObject(jsonObject);
String userStr = jsonObj.getString("userList");
// array
List<User> inventoryDTOs = JSON.parseArray(userStr, User.class);
// object
User user = JSON.parseObject(xx,User.class);
The second JSON array parameter
[{
"name": "zhangsan",
"sex": 1,
"age": 15,
"level": 6
}]
<dependency>
<groupld>net.sf.json-lib</groupld>
<artifactld>json-lib</artifactld>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;
public static void main(String[] args){
// json to jsonarry
JSONArray jsonArray = JSONArray.fromObject(string);
// jsonarry transition object list
List<User> todos = JSONArray.toList(jsonArray, new User() , new JsonConfig());
}
Below is JSONObject turning the body object, using the jar package of Fastjson
User user = JSONObject.toJavaObject(userDto,User.class);
User user = JSON.toJavaObject(userDto,User.class);
JAVA analysis jasonObject Java analysis jsonarray...
In the process of learning Java, we will inevitably encounter to process JSON data formats, and now you will introduce JSON in Java. 1, handle JSONOBJECT 2, handle JSonarray Simple and easy to underst...
1.json-lib-2.4-jdk15 and its dependent jar package Need to pay attention to the compatibility between the dependent jar packages, just importing json-lib is not enough , including the commons-logging-...
Object JSON String Map List Object JsonObject JsonArray Transform Create an entity class Maven address Package that needs to be used JSON string turn object JSON string turns Map JSON string to turn J...
JsonObject and JsonArray Simply put, the Json object is stored in the JsonArray....
1, import dependence 2, write test class Console output:...
JSONOBJECT, JSONARRAY Dependence` JsonObject is simple to use result ``{“name”:234,“id”:123} [{“name”:234,“id”:123}]...