0
我已經仿照我的API結果如下:JsonModel不能轉換陣列,JSON來jsonmodel繼承類
#import "PTPDestination.h"
@interface PTPIndex : PTPBaseEntity
@property (strong, nonatomic) NSNumber * citiesCount;
@property (strong, nonatomic) NSNumber * hotelsCount;
@property (strong, nonatomic) NSArray<PTPDestination *> * top_destinations;
@end
我也仿照PTPDestination這樣的:
@interface PTPDestination : PTPBaseEntity
@property (assign, nonatomic) NSNumber * id;
@property (assign, nonatomic) NSNumber * min_price;
@property (assign, nonatomic) NSNumber * max_discount;
@property (assign, nonatomic) NSString * title;
@end
,我打電話給我的API與AFNetworking是這樣的:
AFHTTPSessionManager * manager = [self createAPISessionManager];
[manager GET:[self createServiceUrlWithMethod:@"someURL"] parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSError * error = nil;
PTPIndex * index = [[PTPIndex alloc] initWithDictionary:responseObject error:&error];
if (error) {
callback (nil, [PTPApiCenteralizedErrorHandler getErrorFromApiError:error task:task responseObject:responseObject]);
return;
}
callback (index, nil);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
callback (nil, [PTPApiCenteralizedErrorHandler getErrorFromApiError:error task:task]);
}];
問題是與目標數組。我不知道爲什麼數組未被轉換爲PTPDestination對象,並且它仍然是一個NSDictionaries數組。
爲什麼會發生這種情況,我如何獲得我的自定義類的數組?
您是否有從服務器返回的JSON有效負載的示例? –
@CraigOtis我稱之爲網址==> www.pintapin.com/service/index/mobile – aakpro
「PTPBaseEntity」是什麼樣的?它是否也擴展'JSONModel'? –