com.jayway.jsonpath.spi.json.JsonProvider.parse()方法的使用及代码示例

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

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

JsonProvider.parse介绍

[英]Parse the given json string
[中]解析给定的json字符串

代码示例

代码示例来源:origin: json-path/JsonPath

/**
   * Evaluate the JSON document at the point of need using the JSON parameter and associated document model which may
   * itself originate from yet another function thus recursively invoking late binding methods.
   *
   * @return
   */
  @Override
  public Object get() {
    return jsonProvider.parse(jsonParameter.getJson());
  }
}

代码示例来源:origin: json-path/JsonPath

@Override
public DocumentContext parse(String json) {
  notEmpty(json, "json string can not be null or empty");
  Object obj = configuration.jsonProvider().parse(json);
  return new JsonContext(obj, configuration);
}

代码示例来源:origin: json-path/JsonPath

/**
 * Applies this JsonPath to the provided json string
 *
 * @param json          a json string
 * @param configuration configuration to use
 * @param <T>           expected return type
 * @return list of objects matched by the given path
 */
@SuppressWarnings({"unchecked"})
public <T> T read(String json, Configuration configuration) {
  notEmpty(json, "json can not be null or empty");
  notNull(configuration, "jsonProvider can not be null");
  return read(configuration.jsonProvider().parse(json), configuration);
}

代码示例来源:origin: json-path/JsonPath

@Override
public DocumentContext parse(InputStream json, String charset) {
  notNull(json, "json input stream can not be null");
  notNull(charset, "charset can not be null");
  try {
    Object obj = configuration.jsonProvider().parse(json, charset);
    return new JsonContext(obj, configuration);
  } finally {
    Utils.closeQuietly(json);
  }
}

代码示例来源:origin: json-path/JsonPath

private static Object parseJson(String json) {
  return Configuration.defaultConfiguration().jsonProvider().parse(json);
}

代码示例来源:origin: json-path/JsonPath

/**
 * Applies this JsonPath to the provided json input stream
 *
 * @param jsonInputStream input stream to read from
 * @param configuration   configuration to use
 * @param <T>             expected return type
 * @return list of objects matched by the given path
 * @throws IOException
 */
@SuppressWarnings({"unchecked"})
public <T> T read(InputStream jsonInputStream, String charset, Configuration configuration) throws IOException {
  notNull(jsonInputStream, "json input stream can not be null");
  notNull(charset, "charset can not be null");
  notNull(configuration, "configuration can not be null");
  try {
    return read(configuration.jsonProvider().parse(jsonInputStream, charset), configuration);
  } finally {
    Utils.closeQuietly(jsonInputStream);
  }
}

代码示例来源:origin: json-path/JsonPath

@Test
public void testFilterWithOrShortCircuit2() throws Exception {
  Object json = Configuration.defaultConfiguration().jsonProvider().parse("{\"firstname\":\"Bob\",\"surname\":\"Smith\",\"age\":30}");
  assertThat(Filter.parse("[?((@.firstname == 'Bob' || @.firstname == 'Jane') && @.surname == 'Smith')]").apply(createPredicateContext(json))).isTrue();
}

代码示例来源:origin: json-path/JsonPath

@Test
public void testFilterWithOrShortCircuit1() throws Exception {
  Object json = Configuration.defaultConfiguration().jsonProvider().parse( "{\"firstname\":\"Bob\",\"surname\":\"Smith\",\"age\":30}");
  assertThat(Filter.parse("[?((@.firstname == 'Bob' || @.firstname == 'Jane') && @.surname == 'Doe')]").apply(createPredicateContext(json))).isFalse();
}

代码示例来源:origin: json-path/JsonPath

@Test
public void shouldMatchJsonPathOnParsedJsonObject() {
  Object json = Configuration.defaultConfiguration().jsonProvider().parse(BOOKS_JSON);
  assertThat(json, hasJsonPath("$.store.name", equalTo("Little Shop")));
}

代码示例来源:origin: json-path/JsonPath

@Test
public void json_evals() {
  String nest = "{\"a\":true}";
  String arr = "[1,2]";
  String json = "{\"foo\":" + arr + ", \"bar\":" + nest + "}";
  Object tree = Configuration.defaultConfiguration().jsonProvider().parse(json);
  Predicate.PredicateContext context = createPredicateContext(tree);
  Filter farr = parse("[?(@.foo == " + arr + ")]");
  //Filter fobjF = parse("[?(@.foo == " + nest + ")]");
  //Filter fobjT = parse("[?(@.bar == " + nest + ")]");
  boolean apply = farr.apply(context);
  assertThat(apply).isEqualTo(true);
  //assertThat(fobjF.apply(context)).isEqualTo(false);
  //assertThat(fobjT.apply(context)).isEqualTo(true);
}

代码示例来源:origin: json-path/JsonPath

@Test
public void filters_can_contain_json_path_expressions() throws Exception {
  Object doc = Configuration.defaultConfiguration().jsonProvider().parse(DOCUMENT);
  assertFalse(filter(where("$.store.bicycle.color").ne("red")).apply(createPredicateContext(doc)));
}

代码示例来源:origin: json-path/JsonPath

@Test
public void not_empty_filter_evaluates() {
  String json = "{\n" +
      "    \"fields\": [\n" +
      "        {\n" +
      "            \"errors\": [], \n" +
      "            \"name\": \"\", \n" +
      "            \"empty\": true \n" +
      "        }, \n" +
      "        {\n" +
      "            \"errors\": [], \n" +
      "            \"name\": \"foo\"\n" +
      "        }, \n" +
      "        {\n" +
      "            \"errors\": [\n" +
      "                \"first\", \n" +
      "                \"second\"\n" +
      "            ], \n" +
      "            \"name\": \"invalid\"\n" +
      "        }\n" +
      "    ]\n" +
      "}\n";
  Object doc = Configuration.defaultConfiguration().jsonProvider().parse(json);
  List<Map<String, Object>> result = JsonPath.read(doc, "$.fields[?]", filter(where("errors").notEmpty()));
  assertEquals(1, result.size());
  List<Map<String, Object>> result2 = JsonPath.read(doc, "$.fields[?]", filter(where("name").notEmpty()));
  assertEquals(2, result2.size());
}

代码示例来源:origin: com.jayway.jsonpath/json-path

/**
   * Evaluate the JSON document at the point of need using the JSON parameter and associated document model which may
   * itself originate from yet another function thus recursively invoking late binding methods.
   *
   * @return
   */
  @Override
  public Object get() {
    return jsonProvider.parse(jsonParameter.getJson());
  }
}

代码示例来源:origin: com.jayway.jsonpath/json-path

@Override
public DocumentContext parse(String json) {
  notEmpty(json, "json string can not be null or empty");
  Object obj = configuration.jsonProvider().parse(json);
  return new JsonContext(obj, configuration);
}

代码示例来源:origin: com.jayway.jsonpath/json-path

/**
 * Applies this JsonPath to the provided json string
 *
 * @param json          a json string
 * @param configuration configuration to use
 * @param <T>           expected return type
 * @return list of objects matched by the given path
 */
@SuppressWarnings({"unchecked"})
public <T> T read(String json, Configuration configuration) {
  notEmpty(json, "json can not be null or empty");
  notNull(configuration, "jsonProvider can not be null");
  return read(configuration.jsonProvider().parse(json), configuration);
}

代码示例来源:origin: com.jayway.jsonpath/json-path

@Override
public DocumentContext parse(InputStream json, String charset) {
  notNull(json, "json input stream can not be null");
  notNull(json, "charset can not be null");
  try {
    Object obj = configuration.jsonProvider().parse(json, charset);
    return new JsonContext(obj, configuration);
  } finally {
    Utils.closeQuietly(json);
  }
}

代码示例来源:origin: com.jayway.jsonpath/json-path

/**
 * Applies this JsonPath to the provided json input stream
 *
 * @param jsonInputStream input stream to read from
 * @param configuration   configuration to use
 * @param <T>             expected return type
 * @return list of objects matched by the given path
 * @throws IOException
 */
@SuppressWarnings({"unchecked"})
public <T> T read(InputStream jsonInputStream, String charset, Configuration configuration) throws IOException {
  notNull(jsonInputStream, "json input stream can not be null");
  notNull(charset, "charset can not be null");
  notNull(configuration, "configuration can not be null");
  try {
    return read(configuration.jsonProvider().parse(jsonInputStream, charset), configuration);
  } finally {
    Utils.closeQuietly(jsonInputStream);
  }
}

代码示例来源:origin: org.apache.calcite/calcite-core

public static Object dejsonize(String input) {
 return JSON_PATH_JSON_PROVIDER.parse(input);
}

代码示例来源:origin: nl.psek.fitnesse/psek-fitnesse-fixtures-general

/**
 * Loads a json string into a json object that will be used by other methods.
 * Supposes UTF-8 encoding
 *
 * @param jsonString input string
 */
public void loadJsonFromString(String jsonString) {
  this.document = Configuration.defaultConfiguration().jsonProvider().parse(new ByteArrayInputStream(jsonString.getBytes()), StandardCharsets.UTF_8.name());
}

代码示例来源:origin: com.github.lafa.jsonpath/json-path

@Override
public DocumentContext parse(InputStream json, String charset) {
  notNull(json, "json input stream can not be null");
  notNull(json, "charset can not be null");
  try {
    Object obj = configuration.jsonProvider().parse(json, charset);
    return new JsonContext(obj, configuration);
  } finally {
    Utils.closeQuietly(json);
  }
}

相关文章