JSON. Help

Source: Internet
Author: User
Using system; using system. net; using system. collections. generic; using system. io; using system. XML; namespace ciceng {public class cicengjson {public object xmltojson () {var xml = file. readalltext (@ "D: \ cnblogs. XML "); // This XML is the backup file xmldocument Doc = new xmldocument (); Doc. loadxml (XML); // get the content var channelxml = Doc under the RSS node. selectsinglenode ("RSS "). innerxml; // further refine the XML format. The content is only the content Doc under the RSS node. loadxml (channelxml); // serialize the XML to JSON and remove the root node var JSON = jsonconvert. serializexmlnode (Doc, newtonsoft. JSON. formatting. none, true);} public object jsontoobject (Object JSON) {var channel = jsonconvert. deserializeobject <channel> (JSON); return channel;} public class channel {Public String title {Get; set;} Public String link {Get; set ;} public String description {Get; set;} Public String language {Get; set;} Public String lastbuilddate {Get; set;} Public String pubdate {Get; set ;} public String TTL {Get; set;} public list <channel_item> item {Get; Set ;}} public class channel_item {Public String title {Get; set ;} public String link {Get; set;} Public String author {Get; set;} Public String pubdate {Get; set;} Public String guid {Get; set ;} public item_description description {Get; set;} public class item_description {// The Node serialized in JSON format using the variable name by default. Because the node content does not comply with the variable definition specification, the specified [jsonproperty ("# CDATA-section")] Public String content {Get; Set ;}}/* // contains is displayed, using Newton. replace javascriptserializer with JSONCode Public override void executeresult (controllercontext context) {If (this. Data! = NULL) {isodatetimeconverter timeformat = new isodatetimeconverter (); timeformat. datetimeformat = "yyyy-mm-dd hh: mm: SS"; response. write (jsonconvert. serializeobject (this. data, newtonsoft. JSON. formatting. indented, timeformat, x);) ;}re-define a controller, name it jsoncontroller, and set it as an abstract class. Then rewrite the method: protected internal virtual jsonresult JSON (Object Data, string contenttype, encoding contentencoding, describehavior) {return New jsonresult {DATA = data, contenttype = contenttype, contentencoding = contentencoding, jsonrequestbehavior = behavior};} changed jsonresult to the class that inherits jsonresult and overwrites the executeresult method! // Configure. */

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.