Hello,
i try to take data from json url. But i get this error
Unable to cast object of type 'Newtonsoft.Json.Linq.JArray' to type 'Newtonsoft.Json.Linq.JObject'.
My Code
Class
public class Eba_Ilkokul
{
public string title { get; set; }
public string hour { get; set; }
public string day { get; set; }
public string classLevel { get; set; }
public string trtLink { get; set; }
public string ebaLink { get; set; }
public string ebaDownloadLink { get; set; }
public string subject { get; set; }
}
Code
string stRead = (new WebClient()).DownloadString("https://onyuzyonetim.eba.gov.tr/api/show/plans/daily?date=2020-10-19&classType=ilkokul");
var jObject = JsonConvert.DeserializeObject<JObject>(stRead).Root.ToList();
List<Eba_Ilkokul> ilkokuls = new List<Eba_Ilkokul>();
int i = 0;
foreach (var item in jObject)
{
if (i < jObject.Count - 1)
{
Eba_Ilkokul ilkokul = new Eba_Ilkokul();
ilkokul.classLevel = ((JProperty)item).Value["classLevel"].ToString().Replace("\"", "");
ilkokul.title = ((JProperty)item).Value["title"].ToString().Replace("\"", "");
ilkokul.hour = ((JProperty)item).Value["hour"].ToString().Replace("\"", "");
ilkokul.day = ((JProperty)item).Value["day"].ToString().Replace("\"", "");
ilkokul.trtLink = ((JProperty)item).Value["trtLink"].ToString().Replace("\"", "");
ilkokul.ebaLink = ((JProperty)item).Value["ebaLink"].ToString().Replace("\"", "");
ilkokul.ebaDownloadLink = ((JProperty)item).Value["ebaDownloadLink"].ToString().Replace("\"", "");
ilkokul.subject = ((JProperty)item).Value["subject"].ToString().Replace("\"", "");
ilkokuls.Add(ilkokul);
}
i++;
}
gvIlkokul.DataSource = ilkokuls;
gvIlkokul.DataBind();
Can help me please? Thanks so much
Line 23:
Line 24: string stRead = (new WebClient()).DownloadString("https://onyuzyonetim.eba.gov.tr/api/show/plans/daily?date=2020-10-19&classType=ilkokul");
Line 25: var jObject = JsonConvert.DeserializeObject<JObject>(stRead).Root.ToList();
Line 26: List<Eba_Ilkokul> ilkokuls = new List<Eba_Ilkokul>();
Line 27: int i = 0;