为什么在反序列化布尔响应时RestSharp会抛出错误?

Jos*_*off 5 restsharp

当我在RestSharp中发出请求时:

var response = client.Execute<bool>(request);
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

"Unable to cast object of type 'System.Boolean' to type 'System.Collections.Generic.IDictionary`2[System.String,System.Object]'."
Run Code Online (Sandbox Code Playgroud)

这是完整的HTTP响应,每个Fiddler:

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 01 Apr 2013 15:09:14 GMT
Content-Length: 5

false
Run Code Online (Sandbox Code Playgroud)

似乎一切都是响应的犹太人,那么是什么给出了?

此外,如果我通过返回一个简单的值而不是一个对象来对我的WebAPI控制器做一些愚蠢的事情并且这将解决我的问题,请随时提出建议.

And*_*ung 9

RestSharp只会反序列化有效的json.false是无效的json(根据RFC-4627).服务器至少需要返回以下内容:

{ "foo": false }
Run Code Online (Sandbox Code Playgroud)

你需要一个类跟随反序列化到:

public class BooleanResponse
{
    public bool Foo { get; set; }
}
Run Code Online (Sandbox Code Playgroud)