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

Source: Internet
Author: User

The permanent address of this article is http://www.cnblogs.com/ChenYilong/p/4044521.html, please indicate the source of reprint.

?

?

-(void) test {

? ? XML Text Example

? ? NSString *testxmlstring = @ "Cake0.55regularchocolateblueberrynoneglazedsugar";

?? ?

? ? NSLog (@ "xml string[\n%@\n]", testxmlstring);

? ? Parse XML as nsdictionary

? ? nserror *parseerror = nil;

? ? nsdictionary *xmldictionary = [XMLReader dictionaryforxmlstring:testxmlstring error:&parseerror];

? ? Print nsdictionary

? ? NSLog (@ "%@", xmldictionary);

?? ?

? ? Nsdictionary conversion to Data

? ? NSData * Jsondata = [nsjsonserializationdatawithjsonobject: xmldictionary options: Nsjsonwritingprettyprintederror:&parseerror];

?? ?

? ? Data converted to JSON

? ? NSString * str = [[nsstringalloc] initwithdata: Jsondata encoding: Nsutf8stringencoding];

?? ?

? ? NSLog (@ "Jsondata string[\n%@\n]", str);

? ? character groups converted to Nsdictionary

? ? nsdictionary *jsondict = [str objectfromjsonstring];

?? ?

? ? Nsdictionary conversion to XML plist format

? ? NSData *xmldata = [nspropertylistserializationdatafrompropertylist: Jsondict

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? format:nspropertylistxmlformat_v1_0

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? errordescription:NULL];

?? ?

? ? Data converted to nsstring output encoded as UTF-8

? ? NSLog(@ "XML:%@", [[nsstringalloc] initwithdata: XmlData Encoding:nsutf8stringencoding]);

?? ?

?? ?

?? ?

? ? NSLog (@ "%@", [XMLWriter xmlstringfromdictionary:jsondict withheader:NO]);

?? ?

}

?

// It uses three class libraries, respectively

1 , jsonkit??? https://github.com/johnezang/jsonkit

2 , XMLWriter?? https://github.com/ahmyi/xmlwriter

3 , XMLReader? https://github.com/amarcadet/xmlreader

?

Source: http://download.csdn.net/download/p709723778/5725585

?

?

The following connections are convert XML to Dictionary

https://github.com/nicklockwood/xmldictionary

http://download.csdn.net/detail/p709723778/6706331

?

?

The permanent address of this article is http://www.cnblogs.com/ChenYilong/p/4044521.html, please specify the source of the reprint.

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.