我正在使用RestRequest对Web服务进行POST。响应是JSON格式,但我在响应中获取它.Content为ASCII,Data为null。代码是:
var request = new RestRequest(api, Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddObject(data);
RestClient client = new RestClient("http://IP:PORT/proto");
client.ExecuteAsync<jLoginResponse>(request, (response) =>
{
var resource = response.Data;
});
这里的response.Data是空的,而Content是 { “UID”: “1234”}
jLoginResponse声明为
[DataContract]
public class jLoginResponse
{
public string uid { get; set; }
}
但它没有像它应该的那样自动反序列化。
答案 0 :(得分:1)
该类的成员应标有DataMember
,如下所示:
[DataContract]
public class jLoginResponse
{
[DataMember]
public string uid { get; set; }
}