How to use Cricket API for building a C# application -
i beginner c# programming. understand concepts of oop know java. have assignment of building desktop application works similar cricbuzz website, i.e supposed show live schedules , score of ongoing cricket matches.
i heard there apis me. found api online issue is, not know how implement or use apis in c# program. please me out here.
tia. :)
entities generated json2csharp. using javascriptserializer
deserialize json , simple sequential webclient
call download json. improve on quality , organization of this, try async, newtonsoft.json serialization, etc. quick , dirty approach out of many out there.
using system.collections.generic; using jsserializer = system.web.script.serialization.javascriptserializer; using system.net; // // http://cricapi.com/api/cricket/ // namespace cricapi.cricket { public class provider { public string url { get; set; } public string source { get; set; } public string pubdate { get; set; } } public class datum { public string title { get; set; } public string description { get; set; } public string unique_id { get; set; } } public class rootobject { public provider provider { get; set; } public list<datum> data { get; set; } public bool cache { get; set; } } } // //http://cricapi.com/api/cricketscore?unique_id=946981 //http://cricapi.com/api/cricketscore?unique_id=946765 // namespace cricapi.cricketscore { public class provider { public string pubdate { get; set; } public string source { get; set; } public string url { get; set; } } public class rootobject { public bool cache { get; set; } public string inningsrequirement { get; set; } public string team2 { get; set; } public string team1 { get; set; } public string score { get; set; } public provider provider { get; set; } } } // // how use // namespace cricapi { class program { static void main (string[] args) { webclient client = new webclient(); // download cricket info // dynamic dyn = jsonconvert.deserializeobject(res); string cricketjson = client.downloadstring("http://cricapi.com/api/cricket/"); cricket.rootobject cro = new jsserializer().deserialize<cricket.rootobject>(cricketjson); // download cricket score info foreach (var datum in cro.data) { string uri = "http://cricapi.com/api/cricketscore?unique_id=" + datum.unique_id; string cricketscorejson = client.downloadstring(uri); cricketscore.rootobject csro = new jsserializer().deserialize<cricketscore.rootobject>(cricketscorejson); } } } }
If you are searching for a platform that provides the information regarding sports odds then choose BetsAPI, where we offer you a better understanding of sports odds!
ReplyDeleteGreat article post!!!
ReplyDeletenice article Thank you for sharing this information with us. CricTez provide live cricket API! solutions for all major sports and leagues. it is very big market to play online. Thanks for sharing this informative and useful blog.