0

我有一个看起来像这样的课程:

@interface AISlideItem: NSObject <NSCoding>
{
    NSString*  PlaceHolderName;
    NSInteger PlaceHolderID;
}
@property (nonatomic, strong) NSString* PlaceHolderName;
@property (nonatomic) NSInteger PlaceHolderID;

@end

@interface AITitleSlideItem : AISlideItem
{
    NSString* Title;
}
@property (nonatomic, strong) NSString* Title;
@end

@interface AIParagraphSlideItem : AISlideItem
{
    NSMutableArray* Paragraphs;
}
@property (nonatomic, strong) NSMutableArray* Paragraphs;
@end

@interface AITextSlideItem : AISlideItem
{
    NSString* Text;
}
@property (nonatomic, strong) NSString* Text;
@end

@interface AIPictureSlideItem : AISlideItem
{
    NSMutableData* Picture;
}
@property (nonatomic, strong) NSMutableData* Picture;
@end

@interface AISlideContent : NSObject
{
    NSString*       LayoutName;
    NSMutableArray* Items;
}
@property (nonatomic,strong) NSString* LayoutName;
@property (nonatomic,strong) NSMutableArray* Items;
@end

@interface ContentParaghraph : NSObject
{
    NSInteger Level;
    NSString* Text;
}
@property (nonatomic) NSInteger Level;
@property (nonatomic, strong) NSString* Text;
@end

我从这些类创建一个复杂的集合,如下所示:

  NSMutableArray* l = [[NSMutableArray alloc]init ];

        AITitleSlideItem* tis1 = [[AITitleSlideItem alloc]init];
        [tis1 setPlaceHolderName:@"I don't think we're using this..."];
        [tis1 setPlaceHolderID:1];
        [tis1 setTitle:@"This is a title"];

        AITextSlideItem* tes1 = [[AITextSlideItem alloc]init];
        [tes1 setPlaceHolderName:@"I don't think we're using this..."];
        [tes1 setPlaceHolderID:2];
        [tes1 setText:@"This is the description"];

        AISlideContent* slide1 = [[AISlideContent alloc]init];
        [slide1 setLayoutName:@"Title content"];
        [[slide1 Items]addObject:tis1];
        [[slide1 Items]addObject:tes1];


        [l addObject:slide1];
        [l addObject:slide1];

我想将 NSMutableArray l 序列化为任何可移植格式,如 json 或 xml。你能发布一些这样做的代码吗?

真挚地

佐利

4

1 回答 1

0

经过进一步调查,我发现没有什么更适合我的需要了。我决定进一步了解 JSON 并创建一个手动创建 JSON 结构的函数。即使花了2-3个小时,也值得所有的努力。

于 2012-06-05T12:11:36.123 回答