AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
這是recommended way發送GET
在AFNetworking 2.0中的請求。我想獲取json中特定鍵的值,因此我想使用responseObject
作爲NSDictionary
。這就是我努力:AFNetworking 2.0 - 使用responseObject作爲NSDictionary
NSError *jsonError = nil;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:(NSData *)responseObject options:kNilOptions error:&jsonError];
它沒有工作:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary bytes]: unrecognized selector sent to instance 0xa048120'
我怎樣才能在responseObject
特定鍵的值?
我有使用AFNetworking類似的問題。我得到一個解析的JSON對象,並需要將其存儲在數組中以備後用。解析的JSON是一個字符串作爲值的字典嗎?我似乎無法使用KVC進入字典,雖然 – noobsmcgoobs