com.alibaba.fastjson.JSONPath.eval()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(578)

本文整理了Java中com.alibaba.fastjson.JSONPath.eval()方法的一些代码示例,展示了JSONPath.eval()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONPath.eval()方法的具体详情如下:
包路径:com.alibaba.fastjson.JSONPath
类名称:JSONPath
方法名:eval

JSONPath.eval介绍

暂无

代码示例

代码示例来源:origin: alibaba/fastjson

public static int size(Object rootObject, String path) {
  JSONPath jsonpath = compile(path);
  Object result = jsonpath.eval(rootObject);
  return jsonpath.evalSize(result);
}

代码示例来源:origin: alibaba/fastjson

/**
 * Compile jsonPath and use it to extract keySet or field names from rootObject.
 * 
 * @param rootObject Can be a map or custom object. Array and Collection are not supported.
 * @param path JSONPath string to be compiled.
 * @return Set of keys, or <code>null</code> if not supported.
 */
public static Set<?> keySet(Object rootObject, String path) {
  JSONPath jsonpath = compile(path);
  Object result = jsonpath.eval(rootObject);
  return jsonpath.evalKeySet(result);
}

代码示例来源:origin: alibaba/fastjson

public static Object eval(Object rootObject, String path) {
  JSONPath jsonpath = compile(path);
  return jsonpath.eval(rootObject);
}

代码示例来源:origin: alibaba/fastjson

/**
 * @since 1.2.9
 * @param json
 * @param path
 * @return
 */
public static Object read(String json, String path) {
  return compile(path)
      .eval(
          JSON.parse(json)
      );
}

代码示例来源:origin: com.alibaba/fastjson

public static int size(Object rootObject, String path) {
  JSONPath jsonpath = compile(path);
  Object result = jsonpath.eval(rootObject);
  return jsonpath.evalSize(result);
}

代码示例来源:origin: com.alibaba/fastjson

/**
 * Compile jsonPath and use it to extract keySet or field names from rootObject.
 * 
 * @param rootObject Can be a map or custom object. Array and Collection are not supported.
 * @param path JSONPath string to be compiled.
 * @return Set of keys, or <code>null</code> if not supported.
 */
public static Set<?> keySet(Object rootObject, String path) {
  JSONPath jsonpath = compile(path);
  Object result = jsonpath.eval(rootObject);
  return jsonpath.evalKeySet(result);
}

代码示例来源:origin: alibaba/fastjson

@SuppressWarnings("rawtypes")
public boolean containsValue(Object rootObject, Object value) {
  Object currentObject = eval(rootObject);
  if (currentObject == value) {
    return true;
  }
  if (currentObject == null) {
    return false;
  }
  if (currentObject instanceof Iterable) {
    Iterator it = ((Iterable) currentObject).iterator();
    while (it.hasNext()) {
      Object item = it.next();
      if (eq(item, value)) {
        return true;
      }
    }
    return false;
  }
  return eq(currentObject, value);
}

代码示例来源:origin: com.alibaba/fastjson

public static Object eval(Object rootObject, String path) {
  JSONPath jsonpath = compile(path);
  return jsonpath.eval(rootObject);
}

代码示例来源:origin: xtuhcy/gecco

public static void main(String[] args) {
    Object json = JSON.parse("{ads:[{id:1},{id:2}],test:'test111'}");
    Object src = com.alibaba.fastjson.JSONPath.eval(json, "$.ads");
    if (src instanceof String) {
      src = JSON.parse(src.toString());
    }
    System.out.println(src);
    Object src2 = com.alibaba.fastjson.JSONPath.eval(json, "$.test");
    if (src2 instanceof String) {
      src2 = JSON.parse(src2.toString());
    }
    System.out.println(src2);
  }
}

代码示例来源:origin: Vedenin/useful-java-links

public  static void main(String[] args) {
  // init class
  Place place = new Place();
  place.setName("World");
  Human human = new Human();
  human.setMessage("Hi");
  human.setPlace(place);
  // convert to json and from json
  String jsonString = JSON.toJSONString(human);
  Human newHuman = JSON.parseObject(jsonString, Human.class);
  // use eval to get info
  Object message = JSONPath.eval(newHuman, "$.message");
  Object world = JSONPath.eval(newHuman, "$.place.name");
  System.out.println(message + " " + world); // print Hi World
}

代码示例来源:origin: com.alibaba/fastjson

/**
 * @since 1.2.9
 * @param json
 * @param path
 * @return
 */
public static Object read(String json, String path) {
  return compile(path)
      .eval(
          JSON.parse(json)
      );
}

代码示例来源:origin: com.alibaba/fastjson

@SuppressWarnings("rawtypes")
public boolean containsValue(Object rootObject, Object value) {
  Object currentObject = eval(rootObject);
  if (currentObject == value) {
    return true;
  }
  if (currentObject == null) {
    return false;
  }
  if (currentObject instanceof Iterable) {
    Iterator it = ((Iterable) currentObject).iterator();
    while (it.hasNext()) {
      Object item = it.next();
      if (eq(item, value)) {
        return true;
      }
    }
    return false;
  }
  return eq(currentObject, value);
}

代码示例来源:origin: com.alibaba/fastjson

if (refValue == null) {
  try {
    refValue = JSONPath.eval(value, ref);
  } catch (JSONPathException ex) {
    && !Map.class.isAssignableFrom(fieldDeser.fieldInfo.fieldClass)) {
  Object root = this.contextArray[0].object;
  refValue = JSONPath.eval(root, ref);

代码示例来源:origin: xtuhcy/gecco

Object src = com.alibaba.fastjson.JSONPath.eval(json, jsonPath);

代码示例来源:origin: xtuhcy/gecco

String jsonPath = JSONPath.value();
Object src = com.alibaba.fastjson.JSONPath.eval(json, jsonPath);
boolean isArray = type.isArray();
boolean isList = ReflectUtils.haveSuperType(type, List.class);// 是List类型

代码示例来源:origin: alibaba/fastjson

return this.eval(root);

代码示例来源:origin: com.alibaba/fastjson

return this.eval(root);

代码示例来源:origin: sd4324530/fastweixin

JSONObject jsonObject = JSONUtil.getJSONFromString(r.getErrmsg());
List buttonList = (List) JSONPath.eval(jsonObject, "$.menu.button");
if (CollectionUtil.isNotEmpty(buttonList)) {
  for (Object button : buttonList) {
    List subList = (List) JSONPath.eval(button, "$.sub_button");
    if (CollectionUtil.isNotEmpty(subList)) {
      for (Object sub : subList) {
        Object type = JSONPath.eval(sub, "$.type");
        JSONPath.set(sub, "$.type", type.toString().toUpperCase());
      Object type = JSONPath.eval(button, "$.type");
      JSONPath.set(button, "$.type", type.toString().toUpperCase());

代码示例来源:origin: bill1012/AdminEAP

@Override
public OAuthUser getOAuthUser(Token accessToken) {
  OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
  this.signRequest(accessToken, request);
  Response response = request.send();
  OAuthUser oAuthUser = new OAuthUser();
  oAuthUser.setoAuthType(getoAuthType());
  Object result = JSON.parse(response.getBody());
  oAuthUser.setoAuthId(JSONPath.eval(result, "$.id").toString());
  oAuthUser.setUserName(JSONPath.eval(result, "$.login").toString());
  return oAuthUser;
}

代码示例来源:origin: sd4324530/fastweixin

JSONObject jsonObject = JSONUtil.getJSONFromString(r.getErrmsg());
List buttonList = (List) JSONPath.eval(jsonObject, "$.menu.button");
if (CollectionUtil.isNotEmpty(buttonList)) {
  for (Object button : buttonList) {
    List subList = (List) JSONPath.eval(button, "$.sub_button");
    if (CollectionUtil.isNotEmpty(subList)) {
      for (Object sub : subList) {
        Object type = JSONPath.eval(sub, "$.type");
        JSONPath.set(sub, "$.type", type.toString().toUpperCase());
      Object type = JSONPath.eval(button, "$.type");
      JSONPath.set(button, "$.type", type.toString().toUpperCase());

相关文章

微信公众号

最新文章

更多