我想创建一个将JSON字符串转换为对象的JSON库。 什么是最清洁的方式来标记与JSON字符串相关的属性? 是否有可能实现的东西像下面的代码目标C - 数据绑定?
注意:下面的代码不能正常工作,它只是一个样本,以显示我想要实现
JSON字符串
{
"FIRST_NAME": "Some first name",
"LAST_NAME": "Some last name"
"CLASSES" :
[
{
"CLASS_NAME": "class 1"
}
{
"CLASS_NAME": "class 2"
}
]
}
型号
@interFace Student
[JSON = "FIRST_NAME"]
@property (nonatomic, retain) NSString *firstName;
[JSON = "LAST_NAME"]
@property (nonatomic, retain) NSString *lastName;
[JSON = "CLASSES"]
@property (nonatomic, retain) NSArray *classes;
@end
JSON方法
@implementation JSON
+ (id)getObjectFromJSONString:(NSString*)string withType:(Class)class
{
//Create a student Object
//for each property if there is a JSON mark look for the value in json string
//populate all available values
//return object
}
@end
是我计划使用JSON框架解析JSON字符串的NSDictionary – aryaxt 2011-04-23 04:11:08