Restsharp104.1 Reverse Order usage

Source: Internet
Author: User

The JSON deserialization class in restsharp is jsondeserializer. Its usage is a little different from that in JSON. net.

(1) set rootelement before deserialization; otherwise, deserialization fails.

(2) If there are several group member variables in the object attributes after deserialization, you must use list <string> instead of string []. Otherwise, the system will prompt that no constructor without parameters is defined.

 

The following example is used to deserialize a json string.

JSON string: {"error": {"code": 400, "message": "unable to complete operation.", "details": ["invalid URL"]}

 

The. NET code is as follows:

 

Public class jsondemo

{

Public void test ()

{

VaR myresponse = new restresponse ();
Myresponse. content = "{\" error \ ": {\" Code \ ": 400, \" message \ ": \" unable to complete operation. \ ", \" details \ ": [\" invalid URL \ "]}";

Jsondeserializer myjsondeserializer = new jsondeserializer ();
Myjsondeserializer. rootelement = "error ";

List <errorobject> myerrors = myjsondeserializer. deserialize <list <errorobject> (myresponse );

}

}

 

Public class errorobject
{
Private int _ code;
Public int code
{
Get {return _ code ;}
Set {_ code = value ;}
}

Private string _ message;
Public String message
{
Get {return _ message ;}
Set {_ message = value ;}
}

Private list <string> _ details;
Public list <string> details
{
Get {return _ details ;}
Set {_ details = value ;}
}

Public errorobject ()
{}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.