-(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