• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java JSONPath类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.alibaba.fastjson.JSONPath的典型用法代码示例。如果您正苦于以下问题:Java JSONPath类的具体用法?Java JSONPath怎么用?Java JSONPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JSONPath类属于com.alibaba.fastjson包,在下文中一共展示了JSONPath类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: 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


示例2: test_map

import com.alibaba.fastjson.JSONPath; //导入依赖的package包/类
public void test_map() throws Exception {
    List<Object> list = new ArrayList<Object>();
    list.add(1001);
    list.add("wenshao");
    
    list.add(Collections.singletonMap("type", "emp"));
    
    Map<String, Object> paths = JSONPath.paths(list);
    
    Assert.assertEquals(5, paths.size());
    Assert.assertSame(list, paths.get("/"));
    Assert.assertEquals(1001, paths.get("/0"));
    Assert.assertEquals("wenshao", paths.get("/1"));
    Assert.assertSame(list.get(2), paths.get("/2"));
    Assert.assertSame(((Map)list.get(2)).get("type"), paths.get("/2/type"));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:JSONPath_paths_test4.java


示例3: test_when_deep_scanning_illegal_property_access_is_ignored

import com.alibaba.fastjson.JSONPath; //导入依赖的package包/类
public void test_when_deep_scanning_illegal_property_access_is_ignored() {
    Object result = JSONPath.eval(
            JSON.parseObject("{\"x\": {\"foo\": {\"bar\": 4}}, \"y\": {\"foo\": 1}}")
            , "$..foo");
    assertEquals(2, ((List) result).size());

    result = JSONPath.eval(
            JSON.parseObject("{\"x\": {\"foo\": {\"bar\": 4}}, \"y\": {\"foo\": 1}}")
            , "$..foo.bar");
    assertEquals(1, ((List) result).size());
    assertEquals(4, ((List) result).get(0));

    result = JSONPath.eval(
            JSON.parseObject("{\"x\": {\"foo\": {\"bar\": 4}}, \"y\": {\"foo\": 1}}")
            , "$..[*].foo.bar");
    assertEquals(1, ((List) result).size());
    assertEquals(4, ((List) result).get(0));

    result = JSONPath.eval(
            JSON.parseObject("{\"x\": {\"foo\": {\"baz\": 4}}, \"y\": {\"foo\": 1}}")
            , "$..[*].foo.bar");
    assertTrue(((List) result).isEmpty());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:DeepScanTest.java


示例4: 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


示例5: test_range

import com.alibaba.fastjson.JSONPath; //导入依赖的package包/类
public void test_range() 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());
    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:4]");
    List<Object> result = (List<Object>) path.eval(list);
    Assert.assertEquals(3, result.size());
    Assert.assertSame(list.get(2), result.get(0));
    Assert.assertSame(list.get(3), result.get(1));
    Assert.assertSame(list.get(4), result.get(2));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:JSONPath_list_range.java


示例6: test_map

import com.alibaba.fastjson.JSONPath; //导入依赖的package包/类
public void test_map() throws Exception {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2017);
    calendar.set(Calendar.MONTH, 6);
    calendar.set(Calendar.DAY_OF_MONTH, 30);

    calendar.set(Calendar.HOUR_OF_DAY, 16);
    calendar.set(Calendar.MINUTE, 8);
    calendar.set(Calendar.SECOND, 43);

    assertEquals(2017, JSONPath.eval(calendar, "/year"));
    assertEquals(6, JSONPath.eval(calendar, "/month"));
    assertEquals(30, JSONPath.eval(calendar, "/day"));

    assertEquals(16, JSONPath.eval(calendar, "/hour"));
    assertEquals(8, JSONPath.eval(calendar, "/minute"));
    assertEquals(43, JSONPath.eval(calendar, "/second"));


}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:JSONPath_calenar_test.java


示例7: test_list_not_in_null

import com.alibaba.fastjson.JSONPath; //导入依赖的package包/类
public void test_list_not_in_null() throws Exception {
    JSONPath path = new JSONPath("[id not in (null)]");
    
    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(4, result.size());
    Assert.assertSame(entities.get(0), result.get(0));
    Assert.assertSame(entities.get(1), result.get(1));
    Assert.assertSame(entities.get(2), result.get(2));
    Assert.assertSame(entities.get(3), result.get(3));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:JSONPath_field_access_filter_in_int.java


示例8: test_for_issue

import com.alibaba.fastjson.JSONPath; //导入依赖的package包/类
public void test_for_issue() throws Exception {

        JSONObject obj = new JSONObject();
        obj.put("data", new JSONObject());
        obj.getJSONObject("data").put("data", new JSONObject());
        obj.getJSONObject("data").getJSONObject("data").put("map", new JSONObject());
        obj.getJSONObject("data").getJSONObject("data").getJSONObject("map").put("21160001", "abc");

        String json = JSON.toJSONString(obj);
        assertEquals("abc", JSONPath.read(json,"data.data.map.21160001"));
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:Issue1445.java


示例9: test_for_issue

import com.alibaba.fastjson.JSONPath; //导入依赖的package包/类
public void test_for_issue() throws Exception {
    String text = "[{\"x\":\"y\"},{\"x\":\"y\"}]";
    List<Model> jsonObject = JSONObject.parseObject(text, new TypeReference<List<Model>>(){});
    System.out.println(JSON.toJSONString(jsonObject));
    String jsonpath = "$..x";
    String value="y2";
    JSONPath.set(jsonObject, jsonpath, value);
    assertEquals("[{\"x\":\"y2\"},{\"x\":\"y2\"}]", JSON.toJSONString(jsonObject));

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:Issue1177_3.java


示例10: test_list_in_3_null

import com.alibaba.fastjson.JSONPath; //导入依赖的package包/类
public void test_list_in_3_null() throws Exception {
    JSONPath path = new JSONPath("[id in (1001, 1003, null)]");
    
    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(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


示例11: test_special

import com.alibaba.fastjson.JSONPath; //导入依赖的package包/类
public void test_special() throws Exception {
    String x = "{\"10.0.0.1\":{\"region\":\"xxx\"}}";
    Object o = JSON.parse(x);
    Assert.assertTrue(JSONPath.contains(o, "$.10\\.0\\.0\\.1"));
    Assert.assertEquals("{\"region\":\"xxx\"}", JSONPath.eval(o, "$.10\\.0\\.0\\.1").toString());
    Assert.assertTrue(JSONPath.contains(o, "$.10\\.0\\.0\\.1.region"));
    Assert.assertEquals("xxx", JSONPath.eval(o, "$.10\\.0\\.0\\.1.region"));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:TestSpecial_1.java


示例12: test_list_in_2

import com.alibaba.fastjson.JSONPath; //导入依赖的package包/类
public void test_list_in_2() throws Exception {
    JSONPath path = new JSONPath("[id in (1001, 1003)]");
    
    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(2, result.size());
    Assert.assertSame(entities.get(0), result.get(0));
    Assert.assertSame(entities.get(2), result.get(1));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:JSONPath_field_access_filter_in_int.java


示例13: test_map

import com.alibaba.fastjson.JSONPath; //导入依赖的package包/类
public void test_map() throws Exception {
    Model model = new Model();
    model.id = 1001;
    model.name = "wenshao";
    model.attributes.put("type", "employee");
    
    Map<String, Object> paths = JSONPath.paths(model);
    
    Assert.assertEquals(5, paths.size());
    Assert.assertSame(model, paths.get("/"));
    Assert.assertEquals(1001, paths.get("/id"));
    Assert.assertEquals("wenshao", paths.get("/name"));
    Assert.assertSame(model.attributes, paths.get("/attributes"));
    Assert.assertEquals("employee", paths.get("/attributes/type"));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:JSONPath_paths_test3.java


示例14: test_map

import com.alibaba.fastjson.JSONPath; //导入依赖的package包/类
public void test_map() throws Exception {
    List<Object> list = new ArrayList<Object>();
    list.add(1001);
    list.add("wenshao");
    
    
    Map<String, Object> paths = JSONPath.paths(list);
    
    Assert.assertEquals(3, paths.size());
    Assert.assertSame(list, paths.get("/"));
    Assert.assertEquals(1001, paths.get("/0"));
    Assert.assertEquals("wenshao", paths.get("/1"));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:JSONPath_paths_test1.java


示例15: test_array

import com.alibaba.fastjson.JSONPath; //导入依赖的package包/类
public void test_array() throws Exception {
    String[] array = new String[]{"1001", "wenshao"};

    Map<String, Object> paths = JSONPath.paths(array);

    Assert.assertEquals(3, paths.size());
    Assert.assertSame(array, paths.get("/"));
    Assert.assertEquals("1001", paths.get("/0"));
    Assert.assertEquals("wenshao", paths.get("/1"));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:JSONPath_paths_test5.java


示例16: 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.java


示例17: test_list_not_like_extract

import com.alibaba.fastjson.JSONPath; //导入依赖的package包/类
public void test_list_not_like_extract() throws Exception {
    JSONPath path = new JSONPath("$[?(@.name not 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, "yakolee"));
    entities.add(new Entity(null, 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_like.java


示例18: test_list_like_left_match

import com.alibaba.fastjson.JSONPath; //导入依赖的package包/类
public void test_list_like_left_match() throws Exception {
    JSONPath path = new JSONPath("$[?(@.name 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(1, result.size());
    Assert.assertSame(entities.get(0), result.get(0));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:JSONPath_field_access_filter_like.java


示例19: 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


示例20: test_list_like_contains

import com.alibaba.fastjson.JSONPath; //导入依赖的package包/类
public void test_list_like_contains() throws Exception {
    JSONPath path = new JSONPath("$[?(@.name 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(1, result.size());
    Assert.assertSame(entities.get(0), result.get(0));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:JSONPath_field_access_filter_like.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java InternalSearchHits类代码示例发布时间:2022-05-23
下一篇:
Java SpeedSearchUtil类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap