本文整理汇总了Java中com.alibaba.fastjson.JSONPath.eval方法的典型用法代码示例。如果您正苦于以下问题:Java JSONPath.eval方法的具体用法?Java JSONPath.eval怎么用?Java JSONPath.eval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.JSONPath
的用法示例。
在下文中一共展示了JSONPath.eval方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_0
import com.alibaba.fastjson.JSONPath; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public void test_0() throws Exception {
Map root = Collections.singletonMap("company", //
Collections.singletonMap("departs", //
Arrays.asList( //
Collections.singletonMap("id",
1001), //
Collections.singletonMap("id",
1002), //
Collections.singletonMap("id", 1003) //
) //
));
List<Object> ids = (List<Object>) JSONPath.eval(root, "$..id");
Assert.assertEquals(3, ids.size());
Assert.assertEquals(1001, ids.get(0));
Assert.assertEquals(1002, ids.get(1));
Assert.assertEquals(1003, ids.get(2));
}
示例2: test_0
import com.alibaba.fastjson.JSONPath; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked" })
public void test_0() throws Exception {
Root root = new Root();
root.company = new Company();
root.company.departs.add(new Department(1001));
root.company.departs.add(new Department(1002));
root.company.departs.add(new Department(1003));
List<Object> ids = (List<Object>) JSONPath.eval(root, "$..id");
Assert.assertEquals(3, ids.size());
Assert.assertEquals(1001, ids.get(0));
Assert.assertEquals(1002, ids.get(1));
Assert.assertEquals(1003, ids.get(2));
}
示例3: test_list_like_left_not_match
import com.alibaba.fastjson.JSONPath; //导入方法依赖的package包/类
public void test_list_like_left_not_match() throws Exception {
JSONPath path = new JSONPath("$[name not like 'ljw%']");
List<Entity> entities = new ArrayList<Entity>();
entities.add(new Entity(1001, "ljw2083"));
entities.add(new Entity(1002, "wenshao"));
entities.add(new Entity(1003, "yakolee"));
entities.add(new Entity(null, null));
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(2, result.size());
Assert.assertSame(entities.get(1), result.get(0));
Assert.assertSame(entities.get(2), result.get(1));
}
示例4: test_list_like_extract
import com.alibaba.fastjson.JSONPath; //导入方法依赖的package包/类
public void test_list_like_extract() throws Exception {
JSONPath path = new JSONPath("$[name like 'ljw2083']");
List<Entity> entities = new ArrayList<Entity>();
entities.add(new Entity(1001, "ljw2083"));
entities.add(new Entity(1002, "wenshao"));
entities.add(new Entity(1003, null));
entities.add(new Entity(null, null));
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(1, result.size());
Assert.assertSame(entities.get(0), result.get(0));
}
示例5: test_list_eq_null
import com.alibaba.fastjson.JSONPath; //导入方法依赖的package包/类
public void test_list_eq_null() throws Exception {
JSONPath path = new JSONPath("$[name = null]");
List<Entity> entities = new ArrayList<Entity>();
entities.add(new Entity(1001, "ljw2083"));
entities.add(new Entity(1002, "wenshao"));
entities.add(new Entity(1003, null));
entities.add(new Entity(null, null));
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(2, result.size());
Assert.assertSame(entities.get(2), result.get(0));
Assert.assertSame(entities.get(3), result.get(1));
}
示例6: test_between_2
import com.alibaba.fastjson.JSONPath; //导入方法依赖的package包/类
public void test_between_2() throws Exception {
List list = new ArrayList();
list.add(new Entity(101, "kiki"));
list.add(new Entity(102, "ljw2083"));
list.add(new Entity(103, "ljw2083"));
List<Object> result = (List<Object>) JSONPath.eval(list, "$[id between 101 and 102]");
Assert.assertEquals(2, result.size());
Assert.assertSame(list.get(0), result.get(0));
Assert.assertSame(list.get(1), result.get(1));
}
示例7: test_range_step
import com.alibaba.fastjson.JSONPath; //导入方法依赖的package包/类
public void test_range_step() throws Exception {
List list = new ArrayList();
list.add(new Object());
list.add(new Object());
list.add(new Object());
list.add(new Object());
list.add(new Object());
JSONPath path = new JSONPath("$[2:8:2]");
List<Object> result = (List<Object>) path.eval(list);
Assert.assertEquals(2, result.size());
Assert.assertSame(list.get(2), result.get(0));
Assert.assertSame(list.get(4), result.get(1));
}
示例8: test_list_map_ge
import com.alibaba.fastjson.JSONPath; //导入方法依赖的package包/类
public void test_list_map_ge() throws Exception {
JSONPath path = new JSONPath("$[?(@.id >= 1002)]");
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(2, result.size());
Assert.assertSame(entities.get(1), result.get(0));
Assert.assertSame(entities.get(2), result.get(1));
}
示例9: test_list_not_null
import com.alibaba.fastjson.JSONPath; //导入方法依赖的package包/类
public void test_list_not_null() throws Exception {
JSONPath path = new JSONPath("$[name != null]");
List<Entity> entities = new ArrayList<Entity>();
entities.add(new Entity(1001, "ljw2083"));
entities.add(new Entity(1002, "wenshao"));
entities.add(new Entity(1003, null));
entities.add(new Entity(null, null));
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(2, result.size());
Assert.assertSame(entities.get(0), result.get(0));
Assert.assertSame(entities.get(1), result.get(1));
}
示例10: test_list_not_in
import com.alibaba.fastjson.JSONPath; //导入方法依赖的package包/类
public void test_list_not_in() throws Exception {
JSONPath path = new JSONPath("[name not in ('ljw2083')]");
List<Entity> entities = new ArrayList<Entity>();
entities.add(new Entity(1001, "ljw2083"));
entities.add(new Entity(1002, "wenshao"));
entities.add(new Entity(1003, "yakolee"));
entities.add(new Entity(1004, null));
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(3, result.size());
Assert.assertSame(entities.get(1), result.get(0));
Assert.assertSame(entities.get(2), result.get(1));
Assert.assertSame(entities.get(3), result.get(2));
}
示例11: test_list_like_right_match
import com.alibaba.fastjson.JSONPath; //导入方法依赖的package包/类
public void test_list_like_right_match() throws Exception {
JSONPath path = new JSONPath("$[?(@.name like '%2083')]");
List<Entity> entities = new ArrayList<Entity>();
entities.add(new Entity(1001, "ljw2083"));
entities.add(new Entity(1002, "wenshao"));
entities.add(new Entity(1003, "yakolee"));
entities.add(new Entity(null, null));
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(1, result.size());
Assert.assertSame(entities.get(0), result.get(0));
}
示例12: test_list_like_not_contains
import com.alibaba.fastjson.JSONPath; //导入方法依赖的package包/类
public void test_list_like_not_contains() throws Exception {
JSONPath path = new JSONPath("$[name not like '%208%']");
List<Entity> entities = new ArrayList<Entity>();
entities.add(new Entity(1001, "ljw2083"));
entities.add(new Entity(1002, "wenshao"));
entities.add(new Entity(1003, "yakolee"));
entities.add(new Entity(null, null));
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(2, result.size());
Assert.assertSame(entities.get(1), result.get(0));
Assert.assertSame(entities.get(2), result.get(1));
}
示例13: test_list_in_3
import com.alibaba.fastjson.JSONPath; //导入方法依赖的package包/类
public void test_list_in_3() throws Exception {
JSONPath path = new JSONPath("[id in (1001, 1003, 1004)]");
List<Entity> entities = new ArrayList<Entity>();
entities.add(new Entity(1001, "ljw2083"));
entities.add(new Entity(1002, "wenshao"));
entities.add(new Entity(1003, "yakolee"));
entities.add(new Entity(1004, null));
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(3, result.size());
Assert.assertSame(entities.get(0), result.get(0));
Assert.assertSame(entities.get(2), result.get(1));
Assert.assertSame(entities.get(3), result.get(2));
}
示例14: test_between_not
import com.alibaba.fastjson.JSONPath; //导入方法依赖的package包/类
public void test_between_not() throws Exception {
List list = new ArrayList();
list.add(new Entity(101, "kiki"));
list.add(new Entity(102, "ljw2083"));
list.add(new Entity(103, "ljw2083"));
List<Object> result = (List<Object>) JSONPath.eval(list, "$[id not between 101 and 102]");
Assert.assertEquals(1, result.size());
Assert.assertSame(list.get(2), result.get(0));
}
示例15: test_list_map
import com.alibaba.fastjson.JSONPath; //导入方法依赖的package包/类
public void test_list_map() throws Exception {
Entity entity = new Entity(123, "wenshao");
JSONPath path = new JSONPath("$['id','name']");
List<Object> result = (List<Object>) path.eval(entity);
Assert.assertSame(entity.getId(), result.get(0));
Assert.assertSame(entity.getName(), result.get(1));
}