iOS development----Nsdictionary,json and XML conversions

Source: Internet
Author: User

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions{     [self test];    //Override point for customization after application Launch.    return YES;}  -(void) Test {        //xml Text Example     nsstring * testxmlstring = @ "Cake0.55regularchocolateblueberrynoneglazedsugar";         nslog (@ "XML string[\n%@\n]", testxmlstring);     //parsing XML is nsdictionary     nserror *parseerror = nil;    nsdictionary *xmldictionary = [XMLReader dictionaryforxmlstring:testxmlstring error:&parseerror];    //Print NSDictionary     nslog (@ "%@", xmldictionary);         // Nsdictionary conversion to data    nsdata* jsondata = [Nsjsonserialization datawithjsonobjecT:xmldictionary options:nsjsonwritingprettyprinted error:&parseerror];         //data converted to json    nsstring* str = [[NSString alloc] initwithdata:jsondata encoding: Nsutf8stringencoding];        nslog (@ "JsonData string[\n%@\n]", str);     //character Group converted to nsdictionary    nsdictionary *jsondict = [str Objectfromjsonstring];        //nsdictionary Convert to XML plist format      nsdata *xmldata = [Nspropertylistserialization datafrompropertylist:jsondict                                                                     format:nspropertylistxmlformat_v1_0                                                          errorDescription:NULL];         //data converted to NSString output encoded as Utf-8    nslog (@ "XML:%@", [[NSString alloc] Initwithdata:xmldata encoding:nsutf8stringencoding]);                nslog (@ "%@", [XMLWriter xmlstringfromdictionary:jsondict withheader:no]);  } //uses three class libraries, respectively, for 1,jsonkit       https://github.com/johnezang/jsonkit2 , XMLWriter    https://github.com/ahmyi/xmlwriter3,xmlreader   https://github.com/ amarcadet/xmlreader SOURCE:http://download.csdn.net/download/p709723778/5725585   The following connection is XML converted to dictionaryhttps://github.com/ nicklockwood/xmldictionaryhttp://download.csdn.net/detail/p709723778/6706331

iOS development----Nsdictionary,json and XML conversions

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.