当前位置: 首页>>代码示例>>Java>>正文


Java JSONPath.eval方法代码示例

本文整理汇总了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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:JSONPath_deepScan_test.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:JSONPath_deepScan_test2.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:JSONPath_field_access_filter_like_simple.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:JSONPath_field_access_filter_like_simple.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:JSONPath_field_access_filter_compare_string_simple.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:JSONPath_between_int.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:JSONPath_list_range.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:JSONPath_field_access_filter_compare_int.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:JSONPath_field_access_filter_compare_string_simple.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:JSONPath_field_access_filter_in_string.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:JSONPath_field_access_filter_like.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:JSONPath_field_access_filter_like_simple.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:JSONPath_field_access_filter_in_int.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:JSONPath_between_int.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:JSONPath_field_access_multi.java


注:本文中的com.alibaba.fastjson.JSONPath.eval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。