【发布时间】:2022-03-15 06:55:37
【问题描述】:
我有以下课程
public class Customer
{
public Customer()
{
Project = new HashSet<Project>();
}
public uint Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public HashSet<Project> Project { get; set; }
}
还有下面的方法
protected async Task<IRestResponse> ApplyRequest<T>(string resource,
Method method, T data) where T: class, new()
{
var client = new RestClient(_connectionConfig.BaseUrl);
client.FollowRedirects = false;
var request = new RestRequest(resource, method);
request.RequestFormat = RestSharp.DataFormat.Json;
request.AddParameter("application/json",
JsonConvert.SerializeObject(data), ParameterType.RequestBody);
//request.AddJsonBody(data);
//This also doesn't work
var response2 = await client.ExecuteTaskAsync<T>(request);
return response2;
}
现在,如果我用 Post 方法调用此方法,返回状态码是“已创建”(实际上是已创建)。但是,属性 IsSuccessful 给出“false”并且错误消息是
“无法将 'SimpleJson.JsonArray' 类型的对象转换为类型 'System.Collections.Generic.IDictionary`2[System.String,System.Object]'。”
这是正常现象,还是我做错了什么? 谢谢
【问题讨论】: