题
我有这个:
public Int32 NumberOfLocationsForCompany(int companyId)
{
var response = _curl.ResetRequest()
.WithPath(LOCATION_URL)
.AddParam("companyId", companyId.ToString())
.RequestAsGet()
.ProcessRequest<Int32>();
return response;
}
.
在最后调用这个。
public T ProcessRequest<T>() where T : new()
{
var response = _client.Execute<T>(_request);
if (response.ErrorException != null)
{
throw response.ErrorException;
}
return response.Data;
}
.
但我收到这个错误。我不明白为什么它试图将一个int映射到一个集合或它是为什么Int64 vs指定的32我指定的32.: 无法施放“system.int64”类型'system.collections.generic.idictionary`2 [system.string,system.object]'。
当我直接击中API时,这就是我回来的东西
.
<int xmlns="http://schemas.microsoft.com/2003/10/Serialization/">17</int>
我觉得它是我不了解休息的东西。我告诉执行方法需要一个int,它收到和int,但试图将其映射到集合。该系列为什么来自哪里?
我注意到,当我查看基本响应对象的内容时,存在适当的结果“17”,为什么无法休息敏锐找到它?仍在哪里找到收集?
解决方案
在查看响应对象时,我发现返回值在数据中的内容vs中。每当我没有返回对象列表时,我发现这是真的。 所以现在,当我期待一个int,string,bool等时,我使用下面并投用返回值的类型:
public string ProcessRequestWithValue()
{
var response = _client.Execute(_request);
if (response.ErrorException != null)
{
throw response.ErrorException;
}
return response.Content;
}
.
希望这有帮助!
不隶属于 StackOverflow