NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:addressId,@"addressId",sendMethod,@"sendMethod",payType,@"payType",subGoodsMdf,@"subGoodsMdf",subGoodsCount,@"subGoodsCount",actIdStr,@"actIdStr",couponId,@"voucherId",scoreNumber,@"exchangeScore",nil];
// 以上情况:如果是中间的某一个字段为nil,则后面的即使不为空也不会显示出来
if (couponId.length) {
[dict setObject:couponId forKey:@"voucherId"];
}
if (scoreNumber>=0) {
[dict setObject:scoreNumber forKey:@"exchangeScore"];
}
本文介绍了使用Objective-C处理NSMutableDictionary的方法,重点讲解了如何根据条件设置字典项,确保只有当特定值有效时才将其添加到字典中。

514

被折叠的 条评论
为什么被折叠?



