// have to remote the dummy data later. public async Task<List<EventItem>> GetEventsFeedData(string url,EventsDataGroup group, bool dummyData) { if (dummyData == true) { List<EventItem> listOfEvents = new List<EventItem>(); for (int i = 1; i < 100; ++i) { EventItem eventItem = new EventItem("Event id - " + i, "Event id - " + i, "Event "+i+" Subtitle", "Assets/event.jpg", "Test Event", "This is a dummy event organized by hackathon", group); listOfEvents.Add(eventItem); } return listOfEvents; } char[] trimchars = { '\"', ' ', '\t', '\n' }; try { string jsonstr = await GetJsonString(url); JsonObject myobj = JsonObject.Parse(jsonstr); JsonObject myres = myobj.GetNamedObject("result"); bool status = myres.GetNamedBoolean("status"); JsonArray data = myres.GetNamedArray("data"); List<EventItem> listOfEvents = new List<EventItem>(); if (status) { //get the list of events foreach (var item in data) { //get the list of key, value pairs in each event Dictionary<string, string> tempdict = new Dictionary<string, string>(); foreach (var details in item.GetObject()) { //textBox1.Text += details.Key + " " + details.Value.Stringify() + "\n"; tempdict.Add(details.Key, details.Value.Stringify()); } EventItem tempitem = new EventItem("","","","","","",group); bool res; string resstr; #region regionEventDetails res = tempdict.TryGetValue("category", out resstr); if (res) { tempitem.category = resstr; } resstr = null; res = tempdict.TryGetValue("contactemail", out resstr); if (res) { tempitem.contactemail = resstr; } resstr = null; res = tempdict.TryGetValue("contactname", out resstr); if (res) { tempitem.contactname = resstr; } resstr = null; res = tempdict.TryGetValue("contactnumber", out resstr); if (res) { tempitem.contactnumber = resstr; } resstr = null; res = tempdict.TryGetValue("description", out resstr); if (res) { tempitem.description = resstr; } resstr = null; res = tempdict.TryGetValue("detailslink", out resstr); if (res) { tempitem.detailslink = resstr; } resstr = null; res = tempdict.TryGetValue("end_date", out resstr); if (resstr != "null" && res) { tempitem.enddate = resstr.Trim(trimchars); } resstr = null; res = tempdict.TryGetValue("start_date", out resstr); if (resstr != "null" && res) { tempitem.startdate = resstr.Trim(trimchars); } resstr = null; res = tempdict.TryGetValue("id", out resstr); if (res) { tempitem.id = Convert.ToInt32(resstr); } resstr = null; res = tempdict.TryGetValue("eventlink", out resstr); if (res) { tempitem.eventlink = resstr; } resstr = null; res = tempdict.TryGetValue("eventtype", out resstr); if (res) { tempitem.eventtype = resstr; } resstr = null; res = tempdict.TryGetValue("location", out resstr); if (res) { tempitem.location = resstr; } resstr = null; res = tempdict.TryGetValue("name", out resstr); if (res) { tempitem.name = resstr.Trim(trimchars); } resstr = null; /* //tempitem.contactemail = tempdict["contactemail"]; //tempitem.contactname = tempdict["contactname"]; //tempitem.contactnumber = tempdict["contactnumber"]; //tempitem.description = tempdict["description"]; //tempitem.detailslink = tempdict["detailslink"]; //tempitem.enddate = tempdict["enddate"]; //tempitem.id = Convert.ToInt32(tempdict["id"]); //tempitem.eventlink = tempdict["eventlink"]; //tempitem.eventtype = tempdict["eventtype"]; //tempitem.location = tempdict["location"]; //tempitem.name = tempdict["name"]; //tempitem.startdate = tempdict["startdate"]; //textBox1.Text += "\n";*/ #endregion listOfEvents.Add(tempitem); } } return listOfEvents; } catch (Exception e) { throw; } }
public async Task<EventsData> GetEventsFeedData(string url) { char[] trimchars = { '\"', ' ', '\t', '\n' }; try { string jsonstr = await GetJsonString(url); JsonObject myobj = JsonObject.Parse(jsonstr); JsonObject myres = myobj.GetNamedObject("result"); bool status = myres.GetNamedBoolean("status"); JsonArray data = myres.GetNamedArray("data"); EventsData eventslist = new EventsData(); if (status) { //get the list of events foreach (var item in data) { //get the list of key, value pairs in each event Dictionary<string, string> tempdict = new Dictionary<string, string>(); foreach (var details in item.GetObject()) { //textBox1.Text += details.Key + " " + details.Value.Stringify() + "\n"; tempdict.Add(details.Key, details.Value.Stringify()); } EventItem tempitem = new EventItem(); bool res; string resstr; #region regionEventDetails res = tempdict.TryGetValue("category", out resstr); if (res) { tempitem.category = resstr; } resstr = null; res = tempdict.TryGetValue("contactemail", out resstr); if (res) { tempitem.contactemail = resstr; } resstr = null; res = tempdict.TryGetValue("contactname", out resstr); if (res) { tempitem.contactname = resstr; } resstr = null; res = tempdict.TryGetValue("contactnumber", out resstr); if (res) { tempitem.contactnumber = resstr; } resstr = null; res = tempdict.TryGetValue("description", out resstr); if (res) { tempitem.description = resstr; } resstr = null; res = tempdict.TryGetValue("detailslink", out resstr); if (res) { tempitem.detailslink = resstr; } resstr = null; res = tempdict.TryGetValue("end_date", out resstr); if (resstr!= "null" && res) { tempitem.enddate = resstr.Trim(trimchars); } resstr = null; res = tempdict.TryGetValue("start_date", out resstr); if (resstr != "null" && res) { tempitem.startdate = resstr.Trim(trimchars); } resstr = null; res = tempdict.TryGetValue("id", out resstr); if (res) { tempitem.id = Convert.ToInt32(resstr); } resstr = null; res = tempdict.TryGetValue("eventlink", out resstr); if (res) { tempitem.eventlink = resstr; } resstr = null; res = tempdict.TryGetValue("eventtype", out resstr); if (res) { tempitem.eventtype = resstr; } resstr = null; res = tempdict.TryGetValue("location", out resstr); if (res) { tempitem.location = resstr; } resstr = null; res = tempdict.TryGetValue("name", out resstr); if (res) { tempitem.name = resstr.Trim(trimchars); } resstr = null; /* //tempitem.contactemail = tempdict["contactemail"]; //tempitem.contactname = tempdict["contactname"]; //tempitem.contactnumber = tempdict["contactnumber"]; //tempitem.description = tempdict["description"]; //tempitem.detailslink = tempdict["detailslink"]; //tempitem.enddate = tempdict["enddate"]; //tempitem.id = Convert.ToInt32(tempdict["id"]); //tempitem.eventlink = tempdict["eventlink"]; //tempitem.eventtype = tempdict["eventtype"]; //tempitem.location = tempdict["location"]; //tempitem.name = tempdict["name"]; //tempitem.startdate = tempdict["startdate"]; //textBox1.Text += "\n";*/ #endregion eventslist.Items.Add(tempitem); } } return eventslist; } catch (Exception e) { throw; } }