i have been stuck in trying to know the syntax for a particular scenario. Please bare with me - i am very new to using json .
Scenario: When I give a string(json) as argument in the URL, I want the url to consume an API and retrieve the details from that API, as per the given input. My project needs deserialization into c# so, i used Newton soft for the same. Say: input is - Profile-id : 123456789 The output should consume details pertaining to that Pid and display.
What i have been doing is :
string url = "http://ift.tt/1Ls0AQo";
string data = GET(url);
dynamic jsonDe = JsonConvert.DeserializeObject(data);
var phyRatings = Convert.ToString(jsonDe.profile.averageRating);
Console.WriteLine(phyRatings);
public string ShowProfile(string pid)
{
}
public static string GET(string url)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
string data = reader.ReadToEnd();
reader.Close();
stream.Close();
return data;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
return null;
}
So, when I pass profile-id as 123456789 in the url, i want the syntax to extract other info with this Profile-id i AM totally confused with the syntax in c#, how I need to pass the argument and what to write inside the ShowProfile function.Searched everywhere but not ale to find the correct syntax. Can someone please tell me if thats the right way to do? Thanks a lot in advance!
Aucun commentaire:
Enregistrer un commentaire