本文整理匯總了Java中com.jayway.jsonpath.JsonPath.compile方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonPath.compile方法的具體用法?Java JsonPath.compile怎麽用?Java JsonPath.compile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.jayway.jsonpath.JsonPath
的用法示例。
在下文中一共展示了JsonPath.compile方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: prepPath
import com.jayway.jsonpath.JsonPath; //導入方法依賴的package包/類
/**
* Assemble an xpath using the given json path and json wrapper.
*
* @param jsonPath definite json path
* @param wrapper object representation of QPP json
* @return xpath that correlates to supplied json path
*/
public static String prepPath(String jsonPath, JsonWrapper wrapper) {
String base = "$";
String leaf = jsonPath;
int lastIndex = jsonPath.lastIndexOf('.');
JsonWrapper metaWrapper = new JsonWrapper(wrapper, false);
if (lastIndex > 0) {
base = jsonPath.substring(0, lastIndex);
leaf = jsonPath.substring(lastIndex + 1);
}
JsonPath compiledPath = JsonPath.compile(base);
Map<String, Object> jsonMap = compiledPath.read(metaWrapper.toString());
Map<String, String> metaMap = getMetaMap(jsonMap, leaf);
String preparedPath = "";
if (metaMap != null) {
preparedPath = makePath(metaMap, leaf);
}
return preparedPath;
}
示例2: assertIsValidJsonPath
import com.jayway.jsonpath.JsonPath; //導入方法依賴的package包/類
/**
* Asserts that the string represents a valid JsonPath expression.
*
* @param path Path expression to validate.
* @param propertyName Name of property.
*/
public void assertIsValidJsonPath(String path, String propertyName) {
if (path == null) {
return;
}
if (path.isEmpty()) {
problemReporter.report(new Problem(this, String.format("%s cannot be empty", propertyName)));
return;
}
try {
JsonPath.compile(path);
} catch (InvalidPathException e) {
problemReporter.report(new Problem(this,
String.format("%s with value '%s' is not a valid JsonPath. %s", propertyName, path,
e.getMessage())));
}
}
示例3: EnsureSimplePatternCompiles
import com.jayway.jsonpath.JsonPath; //導入方法依賴的package包/類
@Test
public void EnsureSimplePatternCompiles() throws Exception {
final JsonPath pattern = JsonPath.compile("$.test");
final Boolean read = pattern.<Boolean>read("{\"test\":true}");
then(read).isTrue();
// Investigate classpath problems (CNFE) in runtime
LoggerFactory.getLogger(JsonPathTest.class);
then(Class.forName("com.jayway.jsonpath.internal.path.CompiledPath")).isNotNull();
}
示例4: validateJsonPath
import com.jayway.jsonpath.JsonPath; //導入方法依賴的package包/類
private static void validateJsonPath(String expr) {
try {
JsonPath.compile(expr);
} catch (Exception e) {
throw new QueryException("expression syntax error: " + expr, e);
}
}
示例5: body
import com.jayway.jsonpath.JsonPath; //導入方法依賴的package包/類
public static Object body(String input, String path) {
JsonPath jsonPath = JsonPath.compile(path);
return jsonPath.read(input);
}
示例6: JsonPathSelector
import com.jayway.jsonpath.JsonPath; //導入方法依賴的package包/類
public JsonPathSelector(String jsonPathStr) {
this.jsonPathStr = jsonPathStr;
this.jsonPath = JsonPath.compile(this.jsonPathStr);
}
示例7: extractFromJson
import com.jayway.jsonpath.JsonPath; //導入方法依賴的package包/類
/**
*
* @param input
* @param path
* @return
*/
public static Object extractFromJson(String input, String path) {
JsonPath jsonPath = JsonPath.compile(path);
return jsonPath.read(input);
}