-(void)test {
    
    //XML文本范例
    NSString *testXMLString = @"Cake0.55RegularChocolateBlueberryNoneGlazedSugar";
    
    NSLog(@"xml string[\n%@\n]", testXMLString);
    // 解析XML为NSDictionary
    NSError *parseError = nil;
    NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLString:testXMLString error:&parseError];
    // 打印 NSDictionary
    NSLog(@"%@", xmlDictionary);
    
    //NSDictionary转换为Data
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:xmlDictionary options:NSJSONWritingPrettyPrinted error:&parseError];
    
    //Data转换为JSON
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    
    NSLog(@"jsonData string[\n%@\n]", str);
    //字符组转换为NSDictionary
    NSDictionary *jsonDict = [str objectFromJSONString];
    
    //NSDictionary转换为XML的plist格式
    NSData *xmlData = [NSPropertyListSerialization dataFromPropertyList:jsonDict
                                                                 format:NSPropertyListXMLFormat_v1_0
                                                       errorDescription:NULL];
    
    //Data转换为NSString输出 编码为UTF-8
    NSLog(@"XML: %@", [[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding]);
    
    
   
    NSLog(@"%@",[XMLWriter XMLStringFromDictionary:jsonDict withHeader:NO]);
 
}
 
//其中用到了三个类库,分别为
1,JSONKit       https://github.com/johnezang/JSONKit
 
 
 
下面连接是XML转换为Dictionary
https://github.com/nicklockwood/XMLDictionary
http://download.csdn.net/detail/p709723778/6706331

XML与JSON的转换的更多相关文章

  1. json:JSONObject包的具体使用(JSONObject-lib包是一个beans,collections,maps,java arrays和xml和JSON互相转换的包)

    1.JSONObject介绍 JSONObject-lib包是一个beans,collections,maps,java arrays和xml和JSON互相转换的包. 2.下载jar包 http:// ...

  2. XML,Object,Json分析转换Xstream采用

    XML,Object,Json转换之浅析Xstream的使用 请尊重他人的劳动成果,转载请注明出处:XML,Object,Json转换之浅析Xstream的使用 XStream的是一个简单的库.主要用 ...

  3. c#中 xml和json 互相转换

    --xml转json XmlDocument doc = new XmlDocument(); doc.LoadXml(result); string json = Newtonsoft.Json.J ...

  4. 个人永久性免费-Excel催化剂功能第90波-xml与json数据结构转换表格结构

    在网络时代,大量的数据交互以xml和json格式提供,特别是系统间的数据交互和网络WebAPI.WebService接口的数据提供,都是通过结构化的xml或json提供给其他应用调用返回数据.若能提供 ...

  5. C#中XML和json互相转换

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Xm ...

  6. java下XML与JSON互相转换的Utils类

    原文:http://heipark.iteye.com/blog/1394844 需要json-lib-2.1-jdk15.jar和xom-1.2.5.jar,maven pom.xml如下: < ...

  7. nodejs XML和json互相转换

    Docs: https://www.npmjs.com/package/fast-xml-parser const xml = ` <user> <name>ajanuw< ...

  8. xStream完美转换XML、JSON

    xStream框架 xStream可以轻易的将Java对象和xml文档相互转换,而且可以修改某个特定的属性和节点名称,而且也支持json的转换: 前面有介绍过json-lib这个框架,在线博文:htt ...

  9. xStream完美转换XML、JSON(转)

    xStream框架 xStream可以轻易的将Java对象和xml文档相互转换,而且可以修改某个特定的属性和节点名称,而且也支持json的转换: 前面有介绍过json-lib这个框架,在线博文:htt ...

随机推荐

  1. Amoeba For MySQL读写分离

    Amoeba安装,参考http://hi.baidu.com/itfenqing/item/79fe989838e1e8ad83d2959c Amoeba版本为:amoeba-mysql-1.3.1- ...

  2. mac自定义安装nodejs步骤

    自定义安装的好处是nodejs相关的文件都在同一个文件夹下,且不与其它程序的文件混合在同一文件夹下. 1.下载node并解压缩:https://nodejs.org/dist/,选择tar.gz包下载 ...

  3. ElasticSearch集群未连接 无法发现节点(windows环境)以及windows环境下设置服务 不能自动启动的问题

    1.无法发现节点的错误: 试验了很多情况,但是总是无法加入集群,后来尝试了一下步骤,问题解决: 1.删除所有数据,重启:无效: 2.统一配置,全部重启,无效: 3.关闭所有防火墙,全部重启,无效: … ...

  4. C# mvc中为Controller或Action添加定制特性实现登录验证

    在本文开始前,先简单讲两个知识点: 1.每个action执行前都会先执行OnActionExecuting方法: 2.FCL提供了多种方式来检测特性的存在,比如IsDefined.GetCustomA ...

  5. Git push 常见用法

        Git push 在使用git commit命令将修改从暂存区提交到本地版本库后,只剩下最后一步将本地版本库的分支推送到远程服务器上对应的分支了,如果不清楚版本库的构成,可以查看我的另一篇,g ...

  6. 帝国CMS内容模板IF判断

    [e:loop={'selfinfo',50,0,0,"jingshu=$navinfor[jingshu]","id"}]<?php$class1=&q ...

  7. 如何用openvr api打开vive前置摄像头

    随着越来越多的开发者开始他们的VR开发工作,他们看到了这项技术的巨大潜力,像是Valve这样的公司正在想办法保证他们的软件开发包(SDK)能够提供尽量多的功能.今天这家公司发布了其针对SteamVR的 ...

  8. Leetcode: Pacific Atlantic Water Flow

    Given an m x n matrix of non-negative integers representing the height of each unit cell in a contin ...

  9. CsvHelper

    写66666行两个数字 用CsvHelper里的ExcelSerializer 400ms SaveAs 200ms 共600ms 直接用StreamWriter 150ms 行数可以超过65536 ...

  10. sdutoj 2606 Rubik’s cube

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2606 Rubik’s cube Time Li ...