Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

consume json using asp.net

hi experts, I just want to learn how to bind json string to asp.net repeater & datatable.
Please show me how. I am not an expert of asp.net framework.

Thanks

Return json string:
[
{"FleetID":6045,"Make":"Kenworth","Model":"T800","FleetMasterType":"Tow","FleetClassType":"Tow Truck","FleetClassSubType":"Heavy Duty Wrecker"},
{"FleetID":6046,"Make":"Freightliner","Model":"Business Class M2 106","FleetMasterType":"Tow","FleetClassType":"Tow Truck","FleetClassSubType":"Medium Duty Trucks Roll-back"}
]


public string GetFleetList(string FleetMasterType, string responseType)
        {
            string RegIDvalue = "0";
            using (System.Net.WebClient client = new System.Net.WebClient())
            {
                var reqparm = new System.Collections.Specialized.NameValueCollection();
                reqparm.Add("FleetMasterType", FleetMasterType);
                byte[] responsebytes = client.UploadValues(domain + "/api/Fleet/GetFleetList?type="+ responseType, "POST", reqparm);
                string responsebody = Encoding.UTF8.GetString(responsebytes);
                if (responseType == "xml")
                {
                    RegIDvalue = GetResponseValue(responsebody, "Fleet", "FleetClassType");
                }
                else
                {
                    RegIDvalue = responsebody;
                }
            }
            return RegIDvalue;
        }

Open in new window

Avatar of ITsolutionWizard
ITsolutionWizard
Flag of United States of America image

ASKER

any helps?
ASKER CERTIFIED SOLUTION
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I just need to know how to bind Json with repeater. 
not calling api because I already done that. Just need a way to treat incoming json to asp repeater.
any helps
protected void Page_Load(object sender, EventArgs e)
{
    string json ="your returned JSON string...";
    Rootobject _objRoot = JsonConvert.DeserializeObject<Rootobject>(json);
    Repeater1.DataSource = _objRoot.root;
    Repeater1.DataBind();
}

Open in new window


Share more information for your working snippet code if you need further assistance.

what is Rootobject ?