美文网首页
XML 格式转JSON 格式

XML 格式转JSON 格式

作者: 宁梓茞 | 来源:发表于2018-01-09 18:25 被阅读0次
#import <Foundation/Foundation.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wobjc-missing-property-synthesis"


typedef NS_ENUM(NSInteger, XMLDictionaryAttributesMode)
{
    XMLDictionaryAttributesModePrefixed = 0, //default
    XMLDictionaryAttributesModeDictionary,
    XMLDictionaryAttributesModeUnprefixed,
    XMLDictionaryAttributesModeDiscard
};


typedef NS_ENUM(NSInteger, XMLDictionaryNodeNameMode)
{
    XMLDictionaryNodeNameModeRootOnly = 0, //default
    XMLDictionaryNodeNameModeAlways,
    XMLDictionaryNodeNameModeNever
};


static NSString *const XMLDictionaryAttributesKey   = @"__attributes";
static NSString *const XMLDictionaryCommentsKey     = @"__comments";
static NSString *const XMLDictionaryTextKey         = @"__text";
static NSString *const XMLDictionaryNodeNameKey     = @"__name";
static NSString *const XMLDictionaryAttributePrefix = @"_";


@interface XMLDictionaryParser : NSObject <NSCopying>

+ (XMLDictionaryParser *)sharedInstance;

@property (nonatomic, assign) BOOL collapseTextNodes; // defaults to YES
@property (nonatomic, assign) BOOL stripEmptyNodes;   // defaults to YES
@property (nonatomic, assign) BOOL trimWhiteSpace;    // defaults to YES
@property (nonatomic, assign) BOOL alwaysUseArrays;   // defaults to NO
@property (nonatomic, assign) BOOL preserveComments;  // defaults to NO
@property (nonatomic, assign) BOOL wrapRootNode;      // defaults to NO

@property (nonatomic, assign) XMLDictionaryAttributesMode attributesMode;
@property (nonatomic, assign) XMLDictionaryNodeNameMode nodeNameMode;

- (NSDictionary *)dictionaryWithParser:(NSXMLParser *)parser;
- (NSDictionary *)dictionaryWithData:(NSData *)data;
- (NSDictionary *)dictionaryWithString:(NSString *)string;
- (NSDictionary *)dictionaryWithFile:(NSString *)path;

@end


@interface NSDictionary (XMLDictionary)

+ (NSDictionary *)dictionaryWithXMLParser:(NSXMLParser *)parser;
+ (NSDictionary *)dictionaryWithXMLData:(NSData *)data;
+ (NSDictionary *)dictionaryWithXMLString:(NSString *)string;
+ (NSDictionary *)dictionaryWithXMLFile:(NSString *)path;

- (NSDictionary *)attributes;
- (NSDictionary *)childNodes;
- (NSArray *)comments;
- (NSString *)nodeName;
- (NSString *)innerText;
- (NSString *)innerXML;
- (NSString *)XMLString;

- (NSArray *)arrayValueForKeyPath:(NSString *)keyPath;
- (NSString *)stringValueForKeyPath:(NSString *)keyPath;
- (NSDictionary *)dictionaryValueForKeyPath:(NSString *)keyPath;

@end


@interface NSString (XMLDictionary)

- (NSString *)XMLEncodedString;

@end


#pragma GCC diagnostic pop

相关文章

  • XML 格式转JSON 格式

  • JSON Schema辅助工具

    JSON在线解析工具(功能包括:JSON格式化、压缩、验证格式、JSON转XML、CSV、YAML),地址如下:h...

  • 数据格式

    XML和JSON数据格式 json数据格式 {"":"", "":"", "":""} json xml对比 1....

  • 干货分享

    工具 json格式化http://json.parser.online.fr/xml 转 jsonhttp://e...

  • H5-12.29Ajax与jquery、xml、json

    四、Ajax的XML 1.请求的数据格式-XML 2.响应的数据格式-XML 五、json JSON - java...

  • XML和JSON数据解析

    XML和JSON是两种数据交换格式。 XML是老牌、经典、灵活的数据交换格式 JSON是比XML轻便的数据交换格式...

  • iOS XML/JSON数据交换格式

    一. XML数据交换格式 XML数据交换格式是一种自描述的数据交互格式,虽然XML数据格式不如JSON "轻便",...

  • ajax中的xml和json

    ajax中的xml 1.请求的数据格式-XML 2.响应的数据格式-XML ajax中的json 一、json 1...

  • Linux下查询外网IP的方法

    Curl 纯文本格式输出: curl JSON格式输出: curl XML格式输出: curl 得到所有IP细节 ...

  • python解析json

    相对于python解析XML来说,我还是比较喜欢json的格式返回,现在一般的api返回都会有json与XML格式...

网友评论

      本文标题:XML 格式转JSON 格式

      本文链接:https://www.haomeiwen.com/subject/zlygnxtx.html