2016-01-22 11:11:41 sevenquan 阅读数 5915

    NSArray *arrays = @[@"1,2,3,4,5,6"];

    NSString *string = [arrays componentsJoinedByString:@","];

    NSArray *array = [string componentsSeparatedByString:@","];

    NSLog(@"=string=--- %@",string);

    NSLog(@"=array=--- %@",array);

2016-03-23 10:27:47 iosWorker 阅读数 13350

1、将数组里面的元素拼接成字符串。

注意:元素本身就是字符。

self.appendString = [stringArrcomponentsJoinedByString:@";"];


2、将字符串根据分隔号转成数组。

//其中 ; 分号必须是 隔断字符串 的分隔符。否则 ; 就要更改成对应的 分隔符 

NSArray* array = [self.appendStringcomponentsSeparatedByString:@";"];


如有更好的建议,请大家不要吝啬,共同进步!!!

2017-02-08 14:21:22 qq_30023981 阅读数 5961
- (NSArray *)stringToJSON:(NSString *)jsonStr {
    if (jsonStr) {
        id tmp = [NSJSONSerialization JSONObjectWithData:[jsonStr dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments | NSJSONReadingMutableLeaves | NSJSONReadingMutableContainers error:nil];
        
        if (tmp) {
            if ([tmp isKindOfClass:[NSArray class]]) {
                
                return tmp;
                
            } else if([tmp isKindOfClass:[NSString class]]
                      || [tmp isKindOfClass:[NSDictionary class]]) {
                
                return [NSArray arrayWithObject:tmp];
                
            } else {
                return nil;
            }
        } else {
            return nil;
        }
        
    } else {
        return nil;
    }
}
2014-12-11 16:13:52 alincexiaohao 阅读数 4723
四个注意点:
1.创建表时,声明字段类型为二进制 blob
NSString *INEditorTableName = @"create table In_Editor(picUrls blob not null)";

2.插入sql语句,把NSArray转换为NSData类型
NSData *dataImageUrls = [NSKeyedArchiver archivedDataWithRootObject:model.imageUrls];

3.不能用 [NSString stringWithFormat: @"sql"];
[_db executeUpdate: @"insert into In_Editor ( picUrls) values (?);",dataImageUrls];

4.读取数据: NSArray *imageArr = [NSKeyedUnarchiver unarchiveObjectWithData:picUrls]

// 如果不注意,上面几点,可能会出现下面错误:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData objectForKey:]: unrecognized selector sent to instance 0x6b46c80'


注:
NSArray 与 NSData的相互转换 二进制
将NSArray转化为NSData类型 :NSData *data = [NSKeyedArchiver archivedDataWithRootObject:Array];
将NSData转化为NSArray类型 :NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data];

Integer:值是signedinteger类型,大小可以是1,2,3,4,6,8bytes
REAL:浮点类型
TEXT:以UTF-8,UTF-16BEorUTF-16LE编码存储的字符类型
BLOB:二进制数据




参考:

http://www.4byte.cn/question/22141/saving-nsarray-in-sqlite-and-retrieving-it.html

http://www.chengxuyuans.com/iPhone_IOS/37789.html


2019-08-20 09:54:34 feiyangkl 阅读数 287

iOS网络请求传入数组

之前做项目的时候,后台要求传入数组,用AFN传入字典,代码入下:



          NSDictionary *parameter = [ NSDictionary dictionary];
            
          NSArray *arr = @[parameter];
            
          NSError *parseError = nil;

          NSData *jsonData = [NSJSONSerialization dataWithJSONObject:arr options:NSJSONWritingPrettyPrinted  error:&parseError];
            
          NSString *jsonstr =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
            
          NSData *objectData = [jsonstr dataUsingEncoding:NSUTF8StringEncoding];
            
          NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:objectData
                                     
                                                                    options:NSJSONReadingMutableContainers
                                     
                                                                      error:&parseError];

ios数组排序

阅读数 131

没有更多推荐了,返回首页