c# - How to convert JSON Array to List<>? -
this json , need access values under each object in attendance array:
{"name":" ","course":"","attendance":[{"name":"international finance","type":"theory","conducted":"55","present":"50"},{"name":"indian constitution","type":"theory","conducted":"6","present":"6"}]}
here code:
public class att { public class attendance { public string name { get; set; } public string type { get; set; } public string conducted { get; set; } public string nowadays { get; set; } } public att(string json) { jobject jobject = jobject.parse(json); jtoken juser = jobject; name = (string)juser["name"]; course of study = (string)juser["course"]; attender = juser["attendance"].tolist<attendance>; } public string name { get; set; } public string course of study { get; set; } public string email { get; set; } //public array attend { get; set; } public list<attendance> attender { get; set; } }
it attender = juser["attendance"].tolist<attendance>;
line have problem with. says,
cannot convert method grouping tolist non-delegate type. did intend invoke method?
how access values?
you have typo!
attendance vs attendence
and should work
attender = juser["attendance"].toobject<list<attendance>>();
you may find running result @ dotnetfiddle
c# json windows-phone
No comments:
Post a Comment