Hi, I'm trying to modify your code to be able to use it when server response is a JSONArray.
Before using your library, in my AFHTTPRequestOperationManager success block, when I make a GET or POST call to my server, I used:
[MyJSONModelClass arrayOfModelsFromData:operation.responseData.....]
to get an NSMutableArray of MyJSONModelClass objects.
But trying to do the same thing (deserialize a JSONArray), in JSONModelSerializer.m, in responseObjectForResponse method, I can't call arrayOfModelsFromData because It's a class method (not an instance method like [[self.clazz alloc] initWithData:validatedData error:error];) and I only have self.clazz.
Si I can't call arrayOfModelsFromData. Can you help me?
I also check if response is a JSONObhect or a JSONArray by doing this (horrible, I think) way:
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:error];
if([json isKindOfClass:[NSArray class]]) {
// jsonModel = <arrayOfModelsFromData call to deserialize the json array that I'm asking for>
} else {
jsonModel = [[self.clazz alloc] initWithData:validatedData error:error];
}
and it works when response is not a JSONArray (else), but I'm sure it have to be a more elegant way to do this, isn't it?
I'm an Android developer and I'm starting to learn Objective-C and Swift, so maybe I'm asking something basic, sorry!
Thanks!
Hi, I'm trying to modify your code to be able to use it when server response is a JSONArray.
Before using your library, in my AFHTTPRequestOperationManager success block, when I make a GET or POST call to my server, I used:
[MyJSONModelClass arrayOfModelsFromData:operation.responseData.....]
to get an NSMutableArray of MyJSONModelClass objects.
But trying to do the same thing (deserialize a JSONArray), in JSONModelSerializer.m, in responseObjectForResponse method, I can't call arrayOfModelsFromData because It's a class method (not an instance method like [[self.clazz alloc] initWithData:validatedData error:error];) and I only have self.clazz.
Si I can't call arrayOfModelsFromData. Can you help me?
I also check if response is a JSONObhect or a JSONArray by doing this (horrible, I think) way:
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:error];
if([json isKindOfClass:[NSArray class]]) {
// jsonModel = <arrayOfModelsFromData call to deserialize the json array that I'm asking for>
} else {
jsonModel = [[self.clazz alloc] initWithData:validatedData error:error];
}
and it works when response is not a JSONArray (else), but I'm sure it have to be a more elegant way to do this, isn't it?
I'm an Android developer and I'm starting to learn Objective-C and Swift, so maybe I'm asking something basic, sorry!
Thanks!