Hi I want to read Id from JSON object which returns from Web Service :
[{"id":11,"username":"test5"}]
Code:
HttpResponseMessage response = null;
using (response = httpClient.PostAsync(url, content).Result)
{
try
{
response.EnsureSuccessStatusCode(); //200 Ok
string responJsonText = response.Content.ReadAsStringAsync().Result;
JObject res = JObject.Parse(responJsonText);
//if ((int)res["id"][0] > 0)
// {
var uid = (int)res["id"][0];
if (uid > 0)
{
return uid;
}
else
{ return 0; }
// }
// else
//{ return 0; }
}
How i can read the Id and username from Json Response using C#?
I get an exception with the following message:
Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path