我有一个如下所示的类列表:
@interface AISlideItem: NSObject
{
NSString* PlaceHolderName;
NSUInteger PlaceHolderID;
}
@property (nonatomic, strong) NSString* PlaceHolderName;
@property (nonatomic) NSUInteger 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
我想将一个包含 AISlideContent 对象的 NSMutableArray 序列化为 json。json 中的每个项目的名称都应该与变量的名称相同。
我怎样才能做到这一点?
这是一个示例 JSON:
{
d: [
{
Items: [
{
placeHolderName: "1",
Title: "Title Slide"
},
{
placeHolderName: "2",
Paragraphs: [
{
Level: 0,
Text: "Title content"
}
]
}
],
LayoutName: "Title"
},
{
Items: [
{
placeHolderName: "1",
Title: "Slide 2"
},
{
placeHolderName: "2",
Paragraphs: [
{
Level: 0,
Text: "Line 1"
},
{
Level: 0,
Text: "Line 2"
},
{
Level: 1,
Text: "Line 2 indented"
},
{
Level: 2,
Text: "Line 3 more indented"
},
{
Level: 0,
Text: "Line 4"
}
]
}
],
LayoutName: "Title and Content"
},
{
Items: [
{
placeHolderName: "1",
Title: "Slide 3"
},
{
placeHolderName: "3",
Picture: [
]
}
],
LayoutName: "Picture above Caption"
}
]
}
ps 我启用了 ARC