国のリストをロードするために、 RestKitを iPhone アプリケーションに使用しています。問題は、elementToPropertyMappings メソッドが辞書を使用して各オブジェクトをマップすることです。私の場合、Country クラスの name プロパティにマップしたい文字列の配列があります。
誰でもこれを行う方法を知っていますか?
elementToPropertyMappings
JSON 要素名からプロパティ アクセサーへのマッピングを含む辞書を返す必要があります
- (NSDictionary *) RKObjectMappable.h で宣言された elementToPropertyMappings
私のJSONデータ
["Argentina","Australia","Austria","Belgium","Bolivia","Brazil","Bulgaria","Canada","Cayman Islands","China","Costa Rica","Croatia","Czech Republic","Denmark","Ecuador","Ethiopia","F.Y.R.O. Macedonia","Finland","France","French Polynesia","Germany","Guam","Hong Kong SAR","Indonesia","Ireland","Israel","Italy","Japan","Latvia","Lithuania","Luxembourg","Malaysia","Malta","Mexico","Morocco","Netherlands","New Zealand","Nicaragua","Norway","Papua New Guinea","Peru","Poland","Portugal","Puerto Rico","Qatar","Romania","Russia","Singapore","Slovakia","Slovenia","South Africa","South Korea","Spain","Sweden","Switzerland","Taiwan","United Arab Emirates","United Kingdom","United States","Venezuela","Vietnam"]
アップデート:
RKClient を使用してリクエストを行う方法を理解したので、マッピング機能はスキップされます。ここで、JSON 解析に使用するクラスを特定する必要があります。yajl-objc パーサーは見栄えがしますが、RestKit のライブラリで実行できる場合は、別のパーサーを含めたくありません。
-(void)loadLocations
{
NSLog(@"loadLocations");
RKObjectManager *objectManager = [RKObjectManager sharedManager];
[[RKClient sharedClient] get:@"/locations/countries.json" delegate:self];
}
- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {
NSLog(@"Loaded payload: %@", [response bodyAsString]);
// HOW CAN I PARSE THIS STRING INTO AN NSArray?
}