You must Sign In to post a response.
  • Category: ASP.NET

    How do use loop for json


    I am stuck in the following code. I need JSON format output. So how to use code for loop using dataset. it is coming output single records

    var strNJson = new
    Series = new
    Status = ds.Tables[0].Rows[0]["Status"].ToString(),
    NCDBSE = ds.Tables[0].Rows[0]["NCDBSE"].ToString()

    public class CombinedModel
    public string NCDName { get; set; }
    public string NCDCode { get; set; }
    public List<SeriesModel> Series { get; set; }

    public class SeriesModel {
    public string Status { get; set; }
    public string NCDBSE { get; set; }
  • #770409
    I believe this is a really simple problem to fix, but I simply can't seem to make my code work!
    Simply looping through a JSON Object and publishing the appropriate Object pieces to my MVC web page is all I'm attempting to achieve.
    Here is my code, which I've kept very simple so that I can get the fundamentals right the first time.
    However, I continue to receive the following error message: "'alertName' does not appear to be defined in Newtonsoft.Json.Linq.JProperty."
    Although I'm conscious that I'm not utilising the Model characteristics right now, I have in the past.
    I sincerely appreciate any assistance.
    var jsonClient = new WebClient();
    jsonClient.Credentials = new NetworkCredential("XXXX", "XXXX");
    jsonClient.Headers.Set("Content-Type", "application/json");
    jsonClient.Headers.Set("Accept", "application/json");
    var alertsSettings = jsonClient.DownloadString("XXXXX:XXXX/api/alerts/settings");

    dynamic alertObj = JsonConvert.DeserializeObject(alertsSettings);

    foreach (var item in alertObj)
    Viewbag.Test123 = item.alertName;

  • Sign In to post your comments