0
我有这个结构,我正在使用System.Net.Http和Newtonsoft以及。 我需要接收web服务响应,并将其转换在我的课,但我不知道该怎么做了HttpResponseMessage和我已经红的职位并没有帮助我。 这是一个Xamarin.forms项目。将HttpResponseMessage转换为对象
public static async Task<User> PostLoginAsync(string login, string senha)
{
using (var client = new HttpClient())
{
try
{
login = "[email protected]";
senha = "1111111";
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("id", "1200"),
new KeyValuePair<string, string>("email", login),
new KeyValuePair<string, string>("password", senha),
new KeyValuePair<string, string>("json", "1"),
});
HttpResponseMessage response = await client.PostAsync("http://ws.site.com", content);
return null;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
return null;
}
}
}
我的课:
class User
{
public string codigo { get; set; }
public string nome { get; set; }
public string email { get; set; }
public string senha { get; set; }
public string imagem { get; set; }
public DateTime dataDeNasc { get; set;}
public string cidade { get; set; }
public string estado { get; set; }
public string telefone { get; set; }
public string sexo { get; set; }
}
如果你能帮助我...我对此表示赞赏。 谢谢反正
“意外的字符在解析值遇到:<路径 '',第0行,位置0”。 这是一个newtonsoft error..I搜索是什么原因导致这个错误,似乎我没有收到一个JSON进行反序列化,实际上它不是一个JSON,然后出现这个错误,但我可以是错了,但有意义 –
我使用: HttpResponseMessage响应=等待client.PostAsync( “mysite的”,内容); VAR转换= response.Content.ReadAsStringAsync()结果。 var user = JsonConvert.DeserializeObject(转换); –
@JoycedeLanna如果你不能确定你收到响应的类型,遇到断点序列化和检查响应或者在邮差或类似的方式检查之前。 – Curiousity