We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
fastjson 1.2.0之后的版本支持JSONPath。
package com.alibaba.fastjson; public class JSONPath { // 构造函数 public JSONPath(String path) {} // 求值方法 public Object eval(Object rootObject) { } }
建议缓存JSONPath对象,这样能够提高求值的性能。
以下两种写法的语义是相同的:
$.store.book[0].title
和
$['store']['book'][0]['title']
public void test_entity() throws Exception { JSONPath path = new JSONPath("$.value"); // 在实际使用中,建议缓存path对象,避免重复创建,这样性能更好 Entity entity = new Entity(); entity.setValue(new Object()); Assert.assertSame(entity.getValue(), path.eval(entity)); } public static class Entity { private Object value; public Object getValue() { return value; } public void setValue(Object value) { this.value = value; } }