0

アプリケーションで JSONModel を使用しています。nil/null NSString を空の文字列 (@"") に変換する JSONValueTransformer でカテゴリを準備することは可能ですか。これまでのところ、json 応答のプロパティが null の場合、オブジェクトのプロパティは @"" になります。

API全体がうまく機能していないため(外部のものです)、すべてのオブジェクトでinitWithDictionaryをオーバーライドすることを避け、NSStringプロパティを持つすべてのJSONModelクラスにValueTransformerのみを使用し、nil/nullの場合は正しい文字列または空の文字列にマップしたいと思います。

4

1 に答える 1

0

応答を取得したら、応答辞書とそのキーを使用して次のループを実行します。

for (id dictionary in [[responseDictionary valueForKey:@"responseKey"] allKeys] )
    {
           ([[responseDictionary valueForKey:@"responseKey"] valueForKey:dictionary] == [NSNull null]) ? [[responseDictionary valueForKey:@"responseKey"] setValue:@"" forKey:dictionary] :[[responseDictionary valueForKey:@"responseKey"] setValue:[[responseDictionary valueForKey:@"responseKey"] valueForKey:dictionary] forKey:dictionary];
    }
于 2016-02-04T11:32:04.777 に答える