码迷,mamicode.com
首页 > 其他好文 > 详细

UTF-8转字典

时间:2015-09-21 19:34:52      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

  NSString *textStr = @"%7B%22buid%22%3A%22%22%2C%22desc%22%3A%22%E4%B8%8D%E5%90%8C%E6%84%8F%E6%82%A8%E7%9A%84%E7%BB%91%E5%AE%9A%E8%AF%B7%E6%B1%82%22%2C%22deviceno%22%3A%22%22%2C%22list%22%3A%5B%5D%2C%22nickname%22%3A%22%E6%9D%A8%E5%B8%86%22%2C%22toNickname%22%3A%223001%22%2C%22type%22%3A%22b%22%7D";
    NSString *str = [textStr stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    str = [str stringByReplacingOccurrencesOfString:@"{" withString:@""];
    str = [str stringByReplacingOccurrencesOfString:@"}" withString:@""];
    NSArray *array = [str componentsSeparatedByString:@","];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        NSString *string = obj;
        string =  [string stringByReplacingOccurrencesOfString:@"\"" withString:@""];
        NSLog(@
"%@",string);
        NSRange range = [string rangeOfString:@
":"];
        [dic setObject:[string substringFromIndex:range.location +1] forKey:[string substringToIndex:range.location]];
    }];
    NSLog(@"%@",dic);
    NSLog(@"%@",dic[@"desc"]);
    for (NSString *str1 in [dic allKeys]) {
        NSLog(@"%@",str1);
    }

 

UTF-8转字典

标签:

原文地址:http://www.cnblogs.com/hxwj/p/4826773.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!