Conversion of XML to JSON

Source: Internet
Author: User

-(void) test {//xml Text ExampleNSString *testxmlstring = @ "Cake0.55regularchocolateblueberrynoneglazedsugar"; NSLog (@ "XML string[\n%@\n]", testxmlstring);//Parse XML as NsdictionaryNserror *parseerror = nil; Nsdictionary *xmldictionary = [XMLReader dictionaryforxmlstring:testxmlstring error:&parseerror];//Print nsdictionaryNSLog (@ "%@", xmldictionary);//nsdictionary conversion to Datansdata* jsondata = [nsjsonserialization datawithjsonobject:xmldictionary options:nsjsonwritingprettyprinted Error: &parseError];//data convert to JSONnsstring* str = [[NSString alloc] Initwithdata:jsondata encoding:nsutf8stringencoding]; NSLog (@ "Jsondata string[\n%@\n]", str);//Character group converted to NsdictionaryNsdictionary *jsondict = [str objectfromjsonstring];//nsdictionary conversion to XML plist format    nsdata *xmldata = [Nspropertylistserialization datafrompropertylist:jsondict                                                                     format:NSPropertyListXMLFormat_v1_0                                                           errordescription:null];    //data converted to nsstring output encoded as UTF-8NSLog (@ "XML:%@", [[NSString alloc] Initwithdata:xmldata encoding:nsutf8stringencoding]); NSLog (@ "%@", [XMLWriter xmlstringfromdictionary:jsondict withheader:no]); }//It uses three class libraries, respectively1,jsonkit https://github.com/johnezang/JSONKit 2,xmlwriter https://github.com/ahmyi/XMLWriter3,XMLReader Https://github.com/amarcadet/XMLReader Source:/http download.csdn.net/download/p709723778/5725585The following connection is XML converted to dictionaryhttps://github.com/nicklockwood/XMLDictionaryhttp://download.csdn.net/detail/p709723778/6706331

Conversion of XML to JSON

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.