я моделируется мой результат апи следующим образом: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
И я называю апи с 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 Я называю этот URL ==> www.pintapin.com/service/index/mobile – aakpro
Как выглядит 'PTPBaseEntity'? Он также расширяет 'JSONModel'? –