Skip to content

Instantly share code, notes, and snippets.

@ttsubono
Created June 25, 2012 11:46
Show Gist options
  • Save ttsubono/2988138 to your computer and use it in GitHub Desktop.
Save ttsubono/2988138 to your computer and use it in GitHub Desktop.
JsonFrameworkで取って来た値をプロパティにセット
// なんか無駄な処理入ってる気がするが・・・、一応残しておく
#import "JSON.h" //JsonFramework
// JSONがNSDictionaryを持つ配列の場合
- (void)something {
id *jsonResult = [result JSONValue];
if (![jsonResult isKindOfClass:[NSArray class]]) return;
NSArray jsonArray = jsonResult;
for (id dic in jsonArray) {
[self setDistanceWithIdType:[[(NSDictionary *)dic objectForKey:@"firstKey"] objectForKey:@"secondKey"]];
}
}
// 値が空のときを判定して、それ以外で値をセット
- (void)setDistanceWithIdType:(id)d {
if (d == nil || d == [NSNull null]) return;
if ([d isKindOfClass:[NSNumber class]]) {
self.distance = [d floatValue];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment