How do I parse a RestSharp response into a class?

Will

I'm using RestSharp to handle sending emails and I need to be able to check the response to make sure everything went okay.

I know absolutely nothing about JSON but what I've seen from my searching has lead me to believe that calling client.Execute<T>( Foo ) should result in me getting an object of type T with properties populated by the result of the request execution...

This is not the case.

In the case where I intentionally fail the POST I get this from the response.Content property :

{"error":3,"message":"Wrong credentials specified"}

When I submit the request with the proper credentials, response.Content looks like this :

{"message":"OK"}

which lead me to believe creating a class like this should be all that I would need :

public class RestMessage {
    string error { get; set; }
    string message { get; set; }
}

but when I call

IRestResponse<RestMessage> Foo = Bar.Execute<RestMessage>( Baz );

Foo.Data equals an object of type RestMessage, but in either case the result is always that error = null ( which makes sense in the latter case, but not in the former ) and message = null.

Clearly it is not as simple as every example I have read makes it out to be.

I have installed RestSharp from NuGet in VS2015 Community using their awesome NuGet... thingy so I have the most recent version.

Can someone explain how I can accomplish what I am trying to do to me as if I were still teething?

Will

Thanks to Gusman for pointing this out.

The answer was so simple I hate myself for not seeing it, and there is now a face-shaped indentation in my desk, and a desk-shaped indentation where my face used to be...

Before :

public class RestMessage{
    string error{ get; set; }
    string message{ get; set; }
}

After :

public class RestMessage{
    public string error{ get; set; }
    public string message{ get; set; }
}

Don't drink and code kids...

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

How do I parse JSON in Racket?

来自分类Dev

How do I override the response content in a JMeter WebDriver sampler test?

来自分类Dev

How do I inspect response headers in laravel 4 for unit testing?

来自分类Dev

How do I parse a JSONArray in Java with Json.simple?

来自分类Dev

How do I receive files via Python's BaseHTTPRequestHandler class?

来自分类Dev

How do I use an extension function in another class? C#

来自分类Dev

How should I parse this data?

来自分类Dev

How do I get a Cookie from a SoapUI response using a Groovy test step?

来自分类Dev

how do i pass the HTTP response from one activity to another activity in android

来自分类Dev

How do I parse my JSON with external middleware now that Express doesn't carry a body parser?

来自分类Dev

RestSharp on Response不知道如何调用回调

来自分类Dev

How do I parse Json with an invalid character for a field name? e.g. { "file/folder": "/Shared/Salesforce/asdf.txt" } with Newtonsoft?

来自分类Dev

How do I fix the output of my fraction class's overloaded + operator?

来自分类Dev

How to transform response from API request into class instance with `class-transformer` in TypeScript?

来自分类Dev

How can I request an Image from a URL when the Response is 302?

来自分类Dev

How to parse a text file (CSV) into haskell so I can operate on it?

来自分类Dev

How can I parse a JSON object with unknown keys?

来自分类常见问题

How do I resolve ClassNotFoundException?

来自分类Dev

Why do I need another constructor in an extended abstract class?

来自分类Dev

How do i sort my listview alphabetically?

来自分类Dev

How do I override a default keybinding in LightTable?

来自分类Dev

How do I modularize polyfills in Angular?

来自分类Dev

How do I declare a driver as global?

来自分类Dev

How do I combine lenses and functors?

来自分类Dev

How do I link to a pdf in AngularJS?

来自分类Dev

How do I include jquery in javafx webview?

来自分类Dev

How do I retrieve the text of a cell comment

来自分类Dev

How do I write a custom module for AngularJS?

来自分类Dev

I do not understand how execlp() works in Linux

Related 相关文章

  1. 1

    How do I parse JSON in Racket?

  2. 2

    How do I override the response content in a JMeter WebDriver sampler test?

  3. 3

    How do I inspect response headers in laravel 4 for unit testing?

  4. 4

    How do I parse a JSONArray in Java with Json.simple?

  5. 5

    How do I receive files via Python's BaseHTTPRequestHandler class?

  6. 6

    How do I use an extension function in another class? C#

  7. 7

    How should I parse this data?

  8. 8

    How do I get a Cookie from a SoapUI response using a Groovy test step?

  9. 9

    how do i pass the HTTP response from one activity to another activity in android

  10. 10

    How do I parse my JSON with external middleware now that Express doesn't carry a body parser?

  11. 11

    RestSharp on Response不知道如何调用回调

  12. 12

    How do I parse Json with an invalid character for a field name? e.g. { "file/folder": "/Shared/Salesforce/asdf.txt" } with Newtonsoft?

  13. 13

    How do I fix the output of my fraction class's overloaded + operator?

  14. 14

    How to transform response from API request into class instance with `class-transformer` in TypeScript?

  15. 15

    How can I request an Image from a URL when the Response is 302?

  16. 16

    How to parse a text file (CSV) into haskell so I can operate on it?

  17. 17

    How can I parse a JSON object with unknown keys?

  18. 18

    How do I resolve ClassNotFoundException?

  19. 19

    Why do I need another constructor in an extended abstract class?

  20. 20

    How do i sort my listview alphabetically?

  21. 21

    How do I override a default keybinding in LightTable?

  22. 22

    How do I modularize polyfills in Angular?

  23. 23

    How do I declare a driver as global?

  24. 24

    How do I combine lenses and functors?

  25. 25

    How do I link to a pdf in AngularJS?

  26. 26

    How do I include jquery in javafx webview?

  27. 27

    How do I retrieve the text of a cell comment

  28. 28

    How do I write a custom module for AngularJS?

  29. 29

    I do not understand how execlp() works in Linux

热门标签

归档