I have a problem. I am receiving the following JSON:
{"Templates":[[{"Id":"30","FileName":"iu6JjcovBwC5LZyU2pRMtXG4l.png"}],[{"Id":"29","FileName":"nJlZFivBzow5fmbR9cxCGOjyH.png"}],[{"Id":"28","FileName":"REpsr0vMkQlhY4AqxcofI1Pan.png"}],[{"Id":"27","FileName":"HIi73dwvZ9Kq5s6yg0eMf4GSc.png"}],[{"Id":"26","FileName":"oSHbkmWxcpfK2G9Fjw6DYzeA8.png"}],[{"Id":"25","FileName":"hKSPDbLqmAiHzBfc1YZTR3X70.png"}],[{"Id":"24","FileName":"53Drk9ZzXHC6bSYavIA02mJRg.png"}],[{"Id":"23","FileName":"ezu82sdroLIYKGSOwP1mxktlF.png"}],[{"Id":"22","FileName":"Z2IyWOpf7GSuU9BvhTrxz3XJw.png"}],[{"Id":"21","FileName":"2rfvThXKE4WLb38cgO5t1IqUw.png"}],[{"Id":"20","FileName":"kjnHiUstO3LEoNW1aG7hMu2CI.png"}],[{"Id":"19","FileName":"rzREfOGthcvPkSdeJ7IgYT26M.png"}],[{"Id":"18","FileName":"sY6AwNBiETSO87fJDjKZU1MVa.png"}],[{"Id":"17","FileName":"OHFnyQtmxi01Iluvd6Mr52AZ3.png"}],[{"Id":"16","FileName":"MQdv5FGAhsDofEran4VBSkI0K.png"}],[{"Id":"15","FileName":"8eb9VfJpqKhPgEdl3SwzrvGBQ.png"}],[{"Id":"14","FileName":"fWDHOAmcMlTYKr6wk70LUCuZV.png"}],[{"Id":"13","FileName":"HNzYXLceV7dgw6vtbBURjC93J.png"}]],"Source":{"TemplateSource":"media/templates/"}}
So I use this code to parse everything:
var jObject = JObject.Parse(json);
var templatePropery = jObject["Templates"] as JArray;
List<Template> templateList = new List<Template>();
foreach (var property in templatePropery)
{
List<Template> propertyList = new List<Template>();
propertyList = JsonConvert.DeserializeObject<List<Template>>(property.ToString());
templateList.AddRange(propertyList);
}
var sourcePropery = jObject["Source"];
foreach (var property in sourcePropery)
{
string tempplateSource = JsonConvert.DeserializeObject<string>(property.ToString());
App.TemplateSource = tempplateSource;
}
Now all the Templates are getting successfully parsed, but the app crashes on the following line:
string tempplateSource = JsonConvert.DeserializeObject<string>(property.ToString());
With the error:
Newtonsoft.Json.JsonReaderException: 'Additional text encountered after finished reading JSON content
What am I doing wrong?