public class SimpleJsonValueExtractor
extends java.lang.Object
String jsonSource = "{\"testArray\":[1,2,3, {\"A\":5,\"B\":7},\"X\"], \"tail\":9}";
SimpleJsonValueExtractor jsonValueExtractor = new SimpleJsonValueExtractor(jsonSource);
if (jsonValueExtractor.select("testArray.[3].A")) {
JsonValue queryResult = jsonValueExtractor.getQueryResult();
if (queryResult == null) {
System.out.println("Query Result = Json null value");
}
else {
System.out.println("Query Result = " + queryResult.toString()); // 5
}
}
else {
System.out.println("[No match found]");
}
| Constructor and Description |
|---|
SimpleJsonValueExtractor(java.io.Reader jsonReader)
Create a new instance from a Json Reader.
|
SimpleJsonValueExtractor(java.lang.String jsonSource)
Create a new instance from a Json String.
|
| Modifier and Type | Method and Description |
|---|---|
JsonValue |
getQueryResult()
Get the extracted simple value (String, long, boolean or null).
|
static java.lang.String |
JsonValueToString(JsonValue jsonValue)
Convert a Json value of any datatype to a string.
|
boolean |
select(java.lang.String simpleQuery)
Select a simple Json value (String, long, boolean or null).
|
public SimpleJsonValueExtractor(java.lang.String jsonSource)
jsonSource - a String containing the Json datapublic SimpleJsonValueExtractor(java.io.Reader jsonReader)
throws java.io.IOException
jsonReader - a Reader for the Json datajava.io.IOException - if somewhat fails.public boolean select(java.lang.String simpleQuery)
simpleQuery - the simple query. Examples: "[0].datapoints.[2].[1]", "customers.person.name"java.lang.IllegalArgumentException - if the root of the Json data is not an Object or Arraypublic JsonValue getQueryResult()
java.lang.RuntimeException - if the query was not successfulpublic static java.lang.String JsonValueToString(JsonValue jsonValue)
jsonValue - the Json value