NSMutableDictionary *elementsMDic = [NSMutableDictionary new];
for (int i = 0 ; i < maxRssiMArray.count; i++) {
NSString *majorStr = [NSString stringWithFormat:@"%@",[maxRssiMArray[i]valueForKey:@"major"]];
NSString *minorStr = [NSString stringWithFormat:@"%@",[maxRssiMArray[i]valueForKey:@"minor"]];
NSInteger rssiInt = [[maxRssiMArray[i] valueForKey:@"rssi"] intValue];
[elementsMDic setValue:@"guest" forKey:@"user_name"];
[elementsMDic setValue:majorStr forKey:@"major"];
[elementsMDic setValue:minorStr forKey:@"minor"];
[elementsMDic setValue:@(rssiInt) forKey:@"rssi"];
[elementsMDic setValue:submitTime forKey:@"submit_time"];
[elementsMDic setValue:HERE_BEACON_UUID forKey:@"beacon_uuid"];
[maxRssiDicMArray addObject:elementsMDic];
}
NSLog(@"%@",maxRssiDicMArray);
我得到的ObjectiveC NSMutableArray中添加的NSMutableDictionary問題
{
"beacon_uuid" = "myUUID";
major = 65535;
minor = 65535;
rssi = "-95";
"submit_time" = "2015-10-29_17:45:56";
"user_name" = guest;
},
我的問題是,爲什麼有些東西得到 「」 別人拿不出 「」 我想應該是這樣的
{
"beacon_uuid" = "myUUID";
"major" = 65535;
"minor" = 65535;
"rssi" = -95;
"submit_time" = "2015-10-29_17:45:56";
"user_name" = "guest";
},
,因爲我的鑰匙都是NSString,而我的主要Str和minorStr都是NSString,也是
請告訴我爲什麼以及如何解決原因!
不是一個壞問題,但肯定代碼是壞的?您枚舉一個數組並重復將值設置爲單個字典。這是不對的。同樣你對'stringWithFormat'和'valueForKey'的使用也是錯誤的;例如,這是正確的(和簡潔):'NSString * majorStr = maxRssiMArray [i] [@「major」];'。 – trojanfoe
對於只有字母且容易理解爲字符串對象的「單個單詞」,它不需要引號。但[對象描述]不是一個問題。 – Larme