我想創建一個將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