c# - Error Cannot deserialize the current JSON array -


i have class

public class rootobject {     public list<award> award { get; set; } } public class award {     public string name { get; set; }     public string year { get; set; } } 

json award

"[{\"name\":\"student of month\",\"year\":\"2017-01-01\"}, {\"name\":\"national hero\",\"year\":\"2017-01-01\"}]" 

i deserialize this

var awardlist = jsonconvert.deserializeobject<rootobject>(award) foreach (var item in awardlist.award) {     profile.awards.add(item); } 

cannot deserialize current json array (e.g. [1,2,3]) type. what's wrong in code?

based on provided json deserializing wrong type. provided json collection of awards @ root.

deserialize like...

var awardlist = jsonconvert.deserializeobject<award[]>(award); foreach (var item in awardlist) {     profile.awards.add(item); } 

the json have below match original code provided

{      "award": [         {"name":"student of month","year":"2017-01-01"},         {"name":"national hero","year":"2017-01-01"}     ] } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -