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