GSON - JsonSyntaxException - Expected name at line 7 column 4
use
catch(JsonSyntaxException e)
instead of
catch(MalformedJsonException e)
because MalformedJsonException is some internal exception while JsonSyntaxException is the one that actually get thrown. here is a code snippet
String response="Something";
JsonElement my_json;
try {
my_json=jsonParser.parse(response);
} catch(JsonSyntaxException e) {
e.printStackTrace();
JsonReader reader = new JsonReader(new StringReader(response));
reader.setLenient(true);
my_json=jsonParser.parse(reader);
}
If this is the actual json: You have an extra comma here and a spelling error. The error says you have bad json syntax. So this is probably one of the first places to look.
{
"objectid" : "test",
"dtype" : "test",
"type" : "test",
"name " : "test",
"description" : "test", //delete this comma
},
{
"objectid" : "test",
"dtyoe" : "test", // spelling error
"type" : "test",
"name " : "test",
"description" : "test"
}
You also seem to be parsing two objects and telling gson you want one result object from it. Consider either parsing the objects separately or tell gson you want a result array Back