0

我在我的应用程序中使用 JSONModel。是否可以使用 JSONValueTransformer 准备将 nil/null NSString 转换为空字符串 (@"") 的类别。到目前为止,当 json 响应中的属性为空时,我在对象中的属性变为 @""。

因为整个 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 回答