I am using json-path
com.jayway.jsonpath:2.4.0`
Java code:
public static void main( String[] args )
{
JSONObject jObject =new JSONObject("{\r\n \"structure\": {\r\n \"tables\": {\r\n \"category\": \"vehicle\"\r\n }\r\n },\r\n \"data\": {}\r\n}") ;
Object jsonPathArray = JsonPath.read(jObject,"$.structure.tables");
System.out.println(jsonPathArray);
}
Exception:
Exception in thread "main" com.jayway.jsonpath.PathNotFoundException: Expected to find an object with property ['structure'] in path $ but found 'org.json.JSONObject'. This is not a json object according to the JsonProvider: 'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'.
at com.jayway.jsonpath.internal.path.PropertyPathToken.evaluate(PropertyPathToken.java:71)
at com.jayway.jsonpath.internal.path.RootPathToken.evaluate(RootPathToken.java:62)
at com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:53)
at com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:61)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:187)
at com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:102)
at com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:89)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:488)
at rxjava.testapp.App.main(App.java:21)
how to solve the above exception?
Thanks