Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 为什么可以';我不能序列化这些数据吗?_Iphone_Objective C - Fatal编程技术网

Iphone 为什么可以';我不能序列化这些数据吗?

Iphone 为什么可以';我不能序列化这些数据吗?,iphone,objective-c,Iphone,Objective C,我想序列化一个数组和一个整数。当我只保存整数时,它就工作了。当我添加数组时,它失败了 NSArray *tempArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docsPath = [tempArray objectAtIndex:0]; tempArray = nil; tempArray = [NSArray

我想序列化一个数组和一个整数。当我只保存整数时,它就工作了。当我添加数组时,它失败了

    NSArray *tempArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docsPath = [tempArray objectAtIndex:0];

    tempArray = nil;
    tempArray = [NSArray arrayWithObjects:
                 ( (someOtherArray != nil) ? (id) someOtherArray : [NSNull null] ),
                 [NSNumber numberWithInt:someIntValue],
                 nil];

    NSString *filePath = [NSString stringWithFormat:@"%@/%@.plist", docsPath, kDataFilename];
    NSString *errString;
    NSData *serializedStrings= [NSPropertyListSerialization
                                dataFromPropertyList:tempArray
                                format:NSPropertyListBinaryFormat_v1_0
                                errorDescription:&errString];
    if( errString != nil ) {
        NSLog(@"SaveData NSpropertyListSerialization error: %@", [errString description]);
        [errString release];
    }

    // returns NO
    BOOL success = [serializedStrings writeToFile:filePath atomically:YES];
数组可能为零,因此我首先检查它。我还尝试了[NSNumber numberWithInt:0]而不是[NSNull null],只是想看看它是否可以代替null工作,但没有


我还得到:NSpropertyListSerialization错误:属性列表对于格式无效

您不能在plist中存储
+[NSNull null]
。您需要一个类似占位符值的变通方法(即使
NSNull
本身就是占位符值…

您不能将
+[NSNull null]
存储在plist中。您需要一个类似占位符值的解决方法(即使
NSNull本身就是占位符值…

那么为什么:((someOtherArray!=nil)?(id)someOtherArray:[NSNumber numberWithInt:0])失败?结果表明,有时数据为nil,并向我提供了NSNull的错误,当我测试数字时,数据在数组中,但是数组中的数据本身有一个序列化错误。谢谢那么为什么:((someOtherArray!=nil);(id)someOtherArray:[NSNumber numberWithInt:0])失败了呢?结果是,有时数据为nil,并给了我NSNull的错误,当我测试数据在数组中的数字时,它与数组中的数据本身有一个序列化错误。谢谢