I have a file query.json that contains [["Rain"], ["Cloudy", "Sprinkler"], [false, true]] to represent a query for a Bayesian network.
String queryContents = readEntireFile(new File("query.json"));
Query query = Query.queryFromString(queryContents);
Is used to read the entire file and then call the method to create the query.
When I call my queryFromString(String s) method I get the error:
Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING
my queryFromString method is
public static Query queryFromString(String s) {
Gson gson = new Gson();
JsonParser parser = new JsonParser();
JsonArray jsonNodes = parser.parse(s).getAsJsonArray();
JsonElement element = jsonNodes.get(0);
JsonArray jsonNode = element.getAsJsonArray();
String [] q = gson.fromJson(jsonNode.get(0), String[].class);
String [] e = gson.fromJson(jsonNode.get(1), String[].class);
boolean[] v = gson.fromJson(jsonNode.get(2), boolean[].class);
return null;
}
This is my first time using JSON, so I' not really sure why it is producing this error, any help?