I'm trying to pass in a JSON file from within an app to populate some views and perform some functions within the app but I keep getting this error.
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
I've gone through most of the previous answers on a similar subject, but none of the solutions are working for me.
This is me passing in my json file.
ArrayList<ControlProperty> controlProperty = new Gson().fromJson("json_file.json", new TypeToken<List<ControlProperty>>() {}.getType());
This is my model.
public class ControlProperty {
private String type;
private String label;
private String name;
private String subtype;
private String dependency;
private String description;
private String placeholder;
private String dependencyType;
private String selectDependencyOption;
private int minlength;
private int maxlength;
private long maxSize;
private String pageType;
private String expectedFormat;
private String maxDate;
private String minDate;
}
and then the json structure
[
{
"type": "Head",
"label": "All fields are necessary.",
"subtype": "h1",
"dependency": "",
"controlId": "frmb-1557846206638-fld-1",
"currentDate": false,
"pageType": "new-page",
"headerSize": "s",
"isFieldDependent": false
},
{
"required": true,
"name": "text-1550823191761",
"type": "text_input",
"label": "Surname",
"minlength": "1",
"maxlength": "50",
"subtype": "text_input",
"dependency": "",
"controlId": "frmb-1557846206638-fld-2",
"currentDate": false,
"pushFieldLink": "surname",
"isFieldDependent": false,
},
{
"name": "text-1550823211048",
"type": "text_input",
"label": "Middle Name",
"minlength": "1",
"maxlength": "50",
"subtype": "text",
"dependency": "",
"controlId": "frmb-1557846206638-fld-3",
"currentDate": false,
"pushFieldLink": "middle_name",
"isFieldDependent": false,
}
]