Ich habe meine api Ergebnis wie folgt modelliert:JsonModel kann kein Array in JSON umwandeln geerbt Klasse 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
ich auch PTPDestination wie folgt modelliert:
@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
Und ich rufe meine api mit AFNetworking wie folgt aus:
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]);
}];
Das Problem ist, mit Reihe von Zielen. Ich weiß nicht, warum das Array nicht in PTPDestination-Objekt konvertiert wird und es als ein Array von NSDictionaries bleibt.
Warum passiert das und wie kann ich ein Array meiner benutzerdefinierten Klasse haben?
Haben Sie ein Beispiel für die JSON-Nutzlast, die von Ihrem Server zurückkommt? –
@CraigOtis Ich nenne diese URL ==> www.pintapin.com/service/index/mobile – aakpro
Wie sieht 'PTPBaseEntity' aus? Erweitert es auch 'JSONModel'? –