为什么Restsharp在Response.Content上包含太多反斜杠?

时间:2017-09-29 04:03:54

标签: c# json asp.net-mvc restsharp

我在asp.net MVC上使用Restsharp v105.2.3。

我的代码

% flutter doctor
[✓] Flutter (on Mac OS X 10.12.6 16G29, locale en-US, channel alpha)
    • Flutter at /Users/frederickcook/flutter
    • Framework revision 701d534ba9 (2 weeks ago), 2017-09-12 14:01:51 -0700
    • Engine revision 31d03de019
    • Tools Dart version 1.25.0-dev.11.0

[✓] Android toolchain - develop for Android devices (Android SDK 26.0.0)
    • Android SDK at /Users/frederickcook/Library/Android/sdk
    • Platform android-26, build-tools 26.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[✓] iOS toolchain - develop for iOS devices (Xcode 9.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.0, Build version 9A235
    • ios-deploy 1.9.2
    • CocoaPods version 1.2.1

[✓] Android Studio (version 2.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[✓] IntelliJ IDEA Community Edition (version 2017.2.5)
    • Flutter plugin version 17.0
    • Dart plugin version 172.4155.35

[✓] Connected devices
    • iPhone 7 • 2AE532E3-5B4B-4D8D-8CFB-F54C3BF6F8EE • ios • iOS 11.0 (simulator)

而不是像这样返回json字符串

var client = new RestClient()
client.BaseUrl = new Uri("http://sample.com/");
var request = new RestRequest("api/users", Method.GET);
request.AddHeader("Authorization", "Bearer " + token);
IRestResponse response = client.Execute(request);

return response.Content;

它在json字符串中添加了更多的反斜杠

"[{\"id\":\"1\",\"name\":\"testuser\"}]"

这使反序列化变得困难。我也测试过使用Postman做同样的请求,它会像这样返回json:

"\"[{\\\"id\\\":\\\"1\\\",\\\"name\\\":\\\"testuser\\\"}]\""

为什么会这样?

0 个答案:

没有答案