您需要在收到此数组后立即将其转换为字典,并丢弃该数组,因为它没用:
#import <Foundation/Foundation.h>
int main(int argc, const char **argv) {
@autoreleasepool {
NSArray *arr = [NSArray arrayWithObjects:@"", @"user_ucurrency_code=USD", @"user_currency_symbol=$",
@"usertypecode=ROBT", @"player_level=1", @"player_isblocked=false", @"lang=en",
@"respond=true", @"flylogin=false", @"str=PageEnd", @"user_balance=100000394.90",
@"user_bonus_balance=0.00", @"first_name=test", @"cash_balance=100000394.90",
@"coupon_balance=0.00", @"str=PageEnd", @"remain_GameCount=0", @"remain_PTAmount=0.00",
@"real_user_balance=100000394.90", @"fun_user_balance=95725.15", @"user_bonus_balance=0.00",
@"bonusstatus=false", @"bonus_id=null", nil];
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
for (NSString *str in arr) {
NSArray *elements = [str componentsSeparatedByString:@"="];
if ([elements count] != 2)
continue;
[dict setValue:[elements objectAtIndex:1]
forKey:[elements objectAtIndex:0]];
}
for (NSString *key in dict) {
NSLog(@"'%@' = '%@'", key, [dict objectForKey:key]); // or valueForKey:
}
}
return 0;
}
$ clang -o test test.m -fobjc-arc -framework Foundation
$ ./test
2013-09-02 12:01:53.811 test[51144:707] 'bonusstatus' = 'false'
2013-09-02 12:01:53.836 test[51144:707] 'lang' = 'en'
2013-09-02 12:01:53.837 test[51144:707] 'cash_balance' = '100000394.90'
2013-09-02 12:01:53.837 test[51144:707] 'flylogin' = 'false'
2013-09-02 12:01:53.838 test[51144:707] 'str' = 'PageEnd'
2013-09-02 12:01:53.838 test[51144:707] 'usertypecode' = 'ROBT'
2013-09-02 12:01:53.839 test[51144:707] 'player_isblocked' = 'false'
2013-09-02 12:01:53.839 test[51144:707] 'player_level' = '1'
2013-09-02 12:01:53.839 test[51144:707] 'respond' = 'true'
2013-09-02 12:01:53.840 test[51144:707] 'remain_PTAmount' = '0.00'
2013-09-02 12:01:53.840 test[51144:707] 'fun_user_balance' = '95725.15'
2013-09-02 12:01:53.841 test[51144:707] 'remain_GameCount' = '0'
2013-09-02 12:01:53.841 test[51144:707] 'user_balance' = '100000394.90'
2013-09-02 12:01:53.842 test[51144:707] 'user_currency_symbol' = '$'
2013-09-02 12:01:53.842 test[51144:707] 'bonus_id' = 'null'
2013-09-02 12:01:53.842 test[51144:707] 'coupon_balance' = '0.00'
2013-09-02 12:01:53.843 test[51144:707] 'real_user_balance' = '100000394.90'
2013-09-02 12:01:53.843 test[51144:707] 'user_bonus_balance' = '0.00'
2013-09-02 12:01:53.848 test[51144:707] 'first_name' = 'test'
2013-09-02 12:01:53.871 test[51144:707] 'user_ucurrency_code' = 'USD'