Jsonフォーマットの簡単な使用例


fastjson
単純解析user_nameプロパティ
String user = ((Map) JSON.parse(token)).get("user_name").toString();

カスタムオブジェクトを解析するには、両方の方法があります.
Student stu1=JSON.parseObject(jsonstr,new TypeReference<Student>(){});

Student stu1=JSON.parseObject(jsonstr,Student.class);

Gson
<dependency>
    <groupId>com.google.code.gsongroupId>
    <artifactId>gsonartifactId>
dependency>
items: [{
    productId: "1423113435324",
    productQuantity: 2
}]
List<OrderDetail> orderDetailList = new ArrayList<>();
try{
     orderDetailList = gson.fromJson(orderForm.getItems(), new TypeToken<List<OrderDetail>>() {
     }.getType());
 } catch (Exception e) {
     log.error("【    】  ,string={}", orderForm.getItems());
     throw new SellException(ResultEnum.PARAM_ERROR);
 }

参考資料
https://blog.csdn.net/srj1095530512/article/details/82529759 https://www.jianshu.com/p/f20ffefeec4d