0

I am working with JSONModel in our group project and came across a problem when the server guys decided to change their response data from TitleCase to camelCase. For the next while, we will need to support both options so I was hoping that since we are already using JSONModel that I could use it's features to fix our problem but I can't seem to find an easy way to do that.

Currently we can do the JSONModel conversion and then after the fact, check for the other (camelCase) keys but I was hoping to do that more generically within JSONModel itself.

I looked into keyMapper but that just lets me change what it is looking for, it won't seem to check for both.

I've tried something like this;

- (void)setCountryCodeWithNSDictionary:(NSDictionary *)dictionary {
    if ([dictionary[@"CountryCode"] isMemberOfClass:[NSString class]]) {
        self.CountryCode = dictionary[@"CountryCode"];
    }
    if ([dictionary[@"countryCode"] isMemberOfClass:[NSString class]]) {
        self.CountryCode = dictionary[@"countryCode"];
    }
}

But that does not seem to work either for some reason.

I guess a more general question would be, how do I make JSONModel key detection be case insensitive?

Any help on this would be greatly appreciated.

Darkin
  • 221
  • 2
  • 4

1 Answers1

0

I would set all keys to their lowercase equivalent when creating my copy of the dictionary and always compare against possibleKey.lowercased()

Mozahler
  • 4,958
  • 6
  • 36
  • 56