Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
I have bulk amount of data. How to get data from JSON and XML using Restsharp or HTTPWebRequest.
Posted

C#
var client = new RestClient("your url");
               var request = new RestRequest("request url ", Method.POST);
               request.AddParameter("email", txtEmail.Text.ToString());
               request.AddParameter("password", txtPassword.Password.ToString());
              client.ExecuteAsync(request, response =>
                {
                    try
                    {
                        var IsSuccess = JsonConvert.DeserializeObject<loginobject>(response.Content);
  

                });
</loginobject>
 
Share this answer
 
v2
string authKey = IsolatedStorageSettings.ApplicationSettings["authKey"] as string;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("web service url");
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";

using (var requestStream = await request.GetRequestStreamAsync())
{
byte[] buffer = Encoding.UTF8.GetBytes("authKey=" + authKey + "&latitude=" + geoposition.Coordinate.Latitude.ToString() + "&longitude=" + geoposition.Coordinate.Longitude.ToString() + "&timeInterval=" + Minutes + "&time=" + updatetime + "&profileStatus=true");
await requestStream.WriteAsync(buffer, 0, buffer.Length);
}


HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync();

using (var reader = new StreamReader(response.GetResponseStream()))
{
string result = await reader.ReadToEndAsync();
}
 
Share this answer
 
XML Document Execution using Restsharp.

C#
var client = new RestClient("Web service url/");

           string url = string.Format("MobileApp/api/JobSeeker/Interview/SessionID/{0}/lng/{1}", sessionID,language);

           var request = new RestRequest(url, Method.GET);

           request.AddParameter("Authorization-Token", "ZJ6/3tldwf1gHj6uMUVSgQ==", ParameterType.HttpHeader);

           client.ExecuteAsync(request, response =>
           {
               InterviewResponse(response.Content);
           });

 private void InterviewResponse(string xmlString)
        {

            XDocument x = XDocument.Parse(xmlString);

            var collections = x.Root.Elements().ToList();
     
            List<interviews> listofJobs = new List<interviews>();

            foreach (var item in collections)
            {
                Interviews job = new Interviews();

                foreach (var el in item.Elements())
                {
                    switch (el.Name.LocalName)
                    {
                        case "EmployerName":
                            job.EmployerName = el.Value;
                            break;
                        case "InterviewType":
                            job.InterviewType = el.Value;
                            break;
                        case "JobCode":
                            job.JobCode = el.Value;
                            break;
                        case "JobTitle":
                            job.JobTitle = el.Value;
                            break;
                        case "Location":
                            job.Location = el.Value;
                            break;
                        case "Schedule":
                            job.Schedule = el.Value;
                            break;
                    }
                }

                listofJobs.Add(job);
            }
           
        }


</interviews></interviews>
 
Share this answer
 
v2
HttpWebRequest listRequest = (HttpWebRequest)HttpWebRequest.Create("web service url");
listRequest.Method = "GET";
listRequest.Accept = "application/atom+xml";
listRequest.ContentType = "application/atom+xml;type=entry";
//listRequest.Credentials = cred;
HttpWebResponse listResponse = (HttpWebResponse)listRequest.GetResponse();
StreamReader listReader = new StreamReader(listResponse.GetResponseStream());
var listXml = new XmlDocument();
listXml.LoadXml(listReader.ReadToEnd());

XmlNodeList xnList = listXml.SelectNodes("/servicelist/service");

//Method 1 Seperate node list
foreach (XmlNode title in xnList)
{
servicelist.Add(new NagiosServices { host_name = title["host_name"].InnerText, display_name = title["display_name"].InnerText, is_active = title["is_active"].InnerText == "1" ? "UP" : "DOWN" });
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900