0

I am simply trying to parse a jsonarray to list of objects but i keep getting an error

Here is the JsonArray

[
"{\"label\":\"Facebook\",\"id\":\"246\",\"Facebook\":\"Yes\",\"date\":\"March-01-2018\"}",
"{\"label\":\"webby\",\"id\":\"247\",\"webby\":\"Yes\",\"date\":\"March-01-2018\"}"
]

and here is the way i try to cast the jsonarray with gson


 Gson gson = new Gson();

 String jsonout = jsonArray.toString();

 Type collectionType = new TypeToken<List<Passwords>>() {}.getType();
 List<Passwords> navigation = gson.fromJson(jsonout, collectionType);

this is the weird error i keep getting

 com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 3 path $[0]

I am simply trying to pass the jsonArray to the list with gson i could really use the help

1 Answers1

0

Your JsonArray is invalid and there shouldn't be quotes (") before and after the curly braces.

It should be

[
   {\"label\":\"Facebook\",\"id\":\"246\",\"Facebook\":\"Yes\",\"date\":\"March-01-2018\"},
   {\"label\":\"webby\",\"id\":\"247\",\"webby\":\"Yes\",\"date\":\"March-01-2018\"}
]
Udith Gunaratna
  • 1,746
  • 1
  • 10
  • 15
  • well this got rid of that error but it only gets me this one: com.google.gson.stream.MalformedJsonException: Expected name at line 1 column 3 path $[0]. im still at a loss here – user3404816 Sep 12 '19 at 07:25