Avatar of ITsolutionWizard
ITsolutionWizard
Flag 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

ASP.NETJSON

Avatar of undefined
Last Comment
ITsolutionWizard

8/22/2022 - Mon
ITsolutionWizard

ASKER
any helps?
ASKER CERTIFIED SOLUTION
David H.H.Lee

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ITsolutionWizard

ASKER
I just need to know how to bind Json with repeater. 
ITsolutionWizard

ASKER
not calling api because I already done that. Just need a way to treat incoming json to asp repeater.
Your help has saved me hundreds of hours of internet surfing.
fblack61
ITsolutionWizard

ASKER
any helps
David H.H.Lee

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.

ITsolutionWizard

ASKER
what is Rootobject ?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.