public string Get(string id) { // TODO: Return the instance of SampleItem with the given id //Temporarily return a static JsonString for Roxanne's testing purposes, will eventually populate with data from schedule image List<SampleItem> SampleResultList = new List<SampleItem>(); for(int i=0; i<10; i++) { // creating a sampleitem at a time and pushing them into a list SampleItem SampleItem = new SampleItem(); SampleItem.CourseName = "Course No.: " + i.ToString(); SampleItem.CourseLocation = "CourseLocation No.: " + i.ToString(); SampleItem.CourseTime = new List<string>(); for(int j=0; j<i ; j++) { SampleItem.CourseTime.Add("DateTime: " + i.ToString() + " " + j.ToString()); } SampleResultList.Add(SampleItem); } JsonOutput JsonOutput = new JsonOutput(); string JsonResult = JsonOutput.ParseToJson(SampleResultList); return JsonResult; }
private String getJSON(String s) { List<SampleItem> SampleResultList = new List<SampleItem>(); String[] lines = s.Split(new String[] {"\n"}, StringSplitOptions.RemoveEmptyEntries); List<String> lineArray = new List<string>(); lineArray.AddRange(lines); String numbers = "0123456789"; String letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; int mod = 0; for (int i = 0; i < lineArray.Count;) { // Remove lines we don't want Boolean found = false; string current = lineArray[i]; for (int a = 0; a < current.Length - 2; a++) { if (mod == 0 || mod == 2) { if (numbers.Contains(current[a].ToString()) && numbers.Contains(current[a + 1].ToString()) && numbers.Contains(current[a + 2].ToString())) { found = true; } } if (mod == 1) { if (current[a].Equals(':') && numbers.Contains(current[a + 1].ToString()) && numbers.Contains(current[a + 2].ToString())) { found = true; } } } if (!found) lineArray.RemoveAt(i); else { i++; mod =(mod + 1) % 3; } } List<String> courses = new List<String>(); for (int i = 0; i < lineArray.Count; i += 3) { if (!courses.Contains(lineArray[i])) { courses.Add(lineArray[i]); } } for (int i = 0; i < courses.Count; i++) { List<int> indices = new List<int>(); for (int x = 0; x < lineArray.Count; x++ ) { if (lineArray[x].Equals(courses[i])) indices.Add(x); } SampleItem SampleItem = new SampleItem(); SampleItem.CourseName = courses[i]; SampleItem.CourseLocation = lineArray[indices[0]+2]; SampleItem.CourseTime = new List<string>(); for (int j = 0; j < indices.Count; j++) { SampleItem.CourseTime.Add(lineArray[indices[j]+1]); } SampleResultList.Add(SampleItem); } JsonOutput JsonOutput = new JsonOutput(); string JsonResult = JsonOutput.ParseToJson(SampleResultList); return JsonResult; }