i new windows phone dev. i'm working on app fetch json web service , parse , display app. used json.net parse it. here's json file:
[ { "id": "001", "title": "title1", "content": "sample content", "category_id": "3", "image": "defaultimg.jpg" }, { "id": "021", "title": "title2", "content": "sample content", "category_id": "1", "image": "defaultimg2.jpg" }, { "id": "011", "title": "title3", "content": "sample content", "category_id": "3", "image": "defaultimg22.jpg" }, { "id": "008", "title": "title24", "content": "sample content", "category_id": "2", "image": "defaultimg12.jpg" }, { "id": "121", "title": "title12", "content": "sample content", "category_id": "3", "image": "defaultimg27.jpg" } ]
so came class of json2csharp.com
public class rootobject { public string id { get; set; } public string title { get; set; } public string content { get; set; } public string category_id { get; set; } public string image { get; set; } }
here's code in cs
var data = new webclient(); observable .fromevent<downloadstringcompletedeventargs>(data, "downloadstringcompleted") .subscribe(r => { var deserialized = jsonconvert.deserializeobject<list<rootobject>>(r.eventargs.result); listbox1.itemssource = deserialized; }); data.downloadstringasync( new uri("http://sampleurl.com/xyz/myjson.aspx"));
i want display has "category_id": "9" on listbox1 can me how filter data? im student , new in c# windows phone. thanks!
you want use linq manipulate list<rootobject>
, like:
var deserialized = jsonconvert.deserializeobject<list<rootobject>>(r.eventargs.result); // select rootobjects category_id equal 9 listbox1.itemssource = deserialized.where(r => r.category_id == 9);
Comments
Post a Comment