Issue
Here i get some values from server
public class iAuth
{
public string resultStatus { get; set; }
public string userName { get; set; }
}
This IAuth i need to bind my data
private async Tas<bool> GetValiedSession(string _SesToken)
{
string Baseurl = WebConfigurationManager.AppSettings["Baseurl"];
var values = new Dictionary<string, string>{
{ "productId", WebConfigurationManager.AppSettings["productId"] },
{ "productKey", WebConfigurationManager.AppSettings["productKey"] },
{ "userName", "gosoddin" },
{ "securityToken",_SesToken },
};
using (var client = new HttpClient())
{
var _json = JsonConvert.SerializeObject(values);
var content = new StringContent(_json, Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await client.PostAsync(Baseurl + "validate/session", content);
//var responseString = await response.Content.ReadAsStringAsync();
IEnumerable<iAuth> aa = await response.Content.ReadAsStringAsync(); ;
// return Ok(responseString);
return true;
}
}
Here how can i bind values to IEnumarable<iAuth>
Here im getting Error as cant convert String to system.colllection.Generic
Solution
You are trying to read the content of your response to IEnumerable<>
IEnumerable<iAuth> aa = await response.Content.ReadAsStringAsync();
But ReadAsStringAsync()
returns string
so that's why the error comes.
So you need to deserialize your Response.Content
to a specific type like,
string response = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<iAuth>(response);
Now you can get resultStatus
and userName
by using like,
string status = result.resultStatus;
string name = result.userName;
Answered By - er-sho
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.