我想你的JSON應該是這樣...
{
"$id": "1",
"EntitySet": [
{
"$id": "2",
"id": 1,
"title1": "Mr"
},
{
"$id": "3",
"id": 2,
"title1": "Ms"
},
{
"$id": "4",
"id": 3,
"title1": "Dr"
},
{
"$id": "5",
"id": 4,
"title1": "Mrs"
},
{
"$id": "6",
"id": 5,
"title1": "N/A"
},
{
"$id": "7",
"id": 6,
"title1": "Other"
}
],
"OperationStatus": true,
"OperationMessage": "Records Available",
"RowsEffected": 0
}
在頂層,這是一個關鍵的「EntitySet的」指向數組的字典。
爲了得到這個成對象...然後
NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:theJSONData options:0 error:nil];
jsonDictionary
這將具有1個的鍵/值對,其中鍵是「EntitySet的」和值是字典的陣列。
EDIT
更新JSON改變的唯一事情之後是該字典將有超過1個鍵/值對。
其他的都一樣。
EDIT 2
然後,您可以保存到一個新的類,這將是這個樣子這個...
@interface MyModelClass : NSObject
@property NSString *id;
@property NSArray *entities;
@property (nonatomic, assign) BOOL operationStatus;
@property NSString *operationMessage;
@property NSNumber *rowsEffected;
- (id)initWithDictionary:(NSDictionary *)dictionary;
@end
然後實施將看起來像......
#import "MyModelClass.h"
@implementation MyModelClass
- (id)initWithDictionary:(NSDictionary *)dictionary
{
self = [super init];
if (self) {
self.id = dictionary[@"$id"];
self.entities = dictionary[@"EntitySet"];
// and so on...
}
return self;
}
@end
然後,當你創建你的jsonDictionary
上面,你可以得到像類...
MyModelClass *myObject = [[MyModelClass alloc] initWithDictionary:jsonDictionary];
ü想提取我想創建新類詞典或別的東西 –
是有可能的是 – Chenna223
存儲的JSONObject * OBJ = JSONObject的objectatindex(I) – Chenna223