C # anonymous serialization and deserialization,

Source: Internet
Author: User

C # anonymous serialization and deserialization,
Preface

We currently advocate frontend and backend separation. After the separation, all services use interfaces to provide services to the front end. When we process custom queries, multiple tables will be queried, when processing multi-table queries, we are too lazy to create a view model, and too many projects are messy. Therefore, the dao layer uses the anonymous type to return json when processing custom queries.

 

Serialization and deserialization
List <object> oData = new List <object> (); oData. add (new {ID = 1, Name = "kd", Age = 31}); oData. add (new {ID = 2, Name = "kb", Age = 32}); string json = fastJSON. JSON. instance. toJSON (oData); Console. writeLine (json); oData = fastJSON. JSON. instance. toObject <List <dynamic> (json); // receives the result from List <object> deserialization with List <dynamic>, after deserialization, access the attribute foreach (dynamic o in oData) {Console. writeLine (o ["ID"] + "," + o ["Name"]);}

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.