我已经和那些遇到同样问题的人尝试过其他答案,但我无法让它发挥作用。另外,我是新手。任何帮助表示赞赏。
当我运行此操作时,我的手机数据为空。
这是我从我的服务中获得的JSON数据。 {" GetDirectoriesResult":" [{\" ID为\":1,\"部门\":\"承认\& #34; \"部来看\":\" \" \"电话\":\" 555-444-4013 \ ",\"评论\":\"按1 \"},{\" id \":2,\&#34 ;部门\":\"门诊手术中心\"," subdepartment \":\" \",\"电话\":\" 555-444-4013 \" \"评论\":\" \"}]&#34 ;}
我的代码
public class PhoneList
{
// public string GetDirectoriesResult { get; set; }
public List<Phone> Phones { get; set; } //- can't get this working
}
public class Phone
{
public int id { get; set; }
public string department { get; set; }
public string subdepartment { get; set; }
public string phone { get; set; }
public string comments { get; set; }
}
public IRestResponse<PhoneList> Execute<PhoneList>(RestRequest request) where PhoneList : new()
{
PhoneList ro = new PhoneList();
var client = new RestClient();
client.BaseUrl = BaseUrl;
// var request = new RestRequest();
request.RequestFormat = DataFormat.Json;
request.AddHeader("Content-Type", "application/json");
request.AddJsonBody(ro);
IRestResponse<PhoneList> response = client.Execute<PhoneList>(request);
if (response.ErrorException != null)
{
const string message = "Error retrieving response. Check inner details for more info.";
var Exception = new ApplicationException(message, response.ErrorException);
throw Exception;
}
return response;
}