Search in sources :

Example 96 with JSONPath

use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.

the class JSONPath_list_range method test_range.

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));
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

JSONPath (com.alibaba.fastjson.JSONPath)96 List (java.util.List)77 ArrayList (java.util.ArrayList)76 HashMap (java.util.HashMap)6 JSONException (com.alibaba.fastjson.JSONException)2 Entity (com.alibaba.json.bvt.path.JSONPath_between_int.Entity)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1