Snack3 3.1.10的新特性及应用

<dependency>
  <groupId>org.noear</groupId>
  <artifactId>snack3</artifactId>
  <version>3.1.10</version>
</dependency>

(一)增加特性:Feature.StringJsonToNode

//注意:data 的值是个 string
String json = "{id:1,name:'x', data:'{user_id:6}'}";

ONode oNode = ONode.loadStr(json, Feature.StringJsonToNode);

int user_id = oNode.get("data").get("user_id").getInt();
//或用Jsonpath: int user_id = oNode.select("data.user_id").getInt();

//assert user_id == 6;

(二)增加接口:ONode::fillObj(),ONode::fillStr()

String json = "{id:1,name:'x', data:{user_id:6,icon:'fa1',type:2}}";

ONode oNode = ONode.loadStr(json);

//用新的 Json string 填充 data 的内容
oNode.get("data").fillStr("{user_id:8,mobile:'123'}");

int user_id = oNode.get("data").get("user_id").getInt();

//assert user_id == 8;

(三)增强接口:ONode::set(key, obj),ONode::val(obj)

List<Object> list = new ArrayList<>();
list.add(1);
list.add("a");

Map<String,Object> map = new LinkedHashMap<>();
map.put("k1",1);
map.put("k2","a");

ONode oNode = new ONode();

oNode.set("map", map);
oNode.set("list",list);

oNode.get("list2").val(list);
posted @ 2020-09-04 11:14  带刺的坐椅  阅读(243)  评论(0编辑  收藏  举报