Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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
Objective c 无法将从.Net web服务返回的Json反序列化的NSDictionary保存到Plist_Objective C_Json_Plist - Fatal编程技术网

Objective c 无法将从.Net web服务返回的Json反序列化的NSDictionary保存到Plist

Objective c 无法将从.Net web服务返回的Json反序列化的NSDictionary保存到Plist,objective-c,json,plist,Objective C,Json,Plist,我有一个.net webservice,它以以下格式返回Json数据: NSDictionary *json = [NSJSONSerialization JSONObjectWithData:dataPlist options:NSJSONReadingMutableContainers error:&errorJson]; [ { "MEMBERID": "xxx", "PREFIXINFORMAL": "Mr.", "FIRSTNAME":

我有一个.net webservice,它以以下格式返回Json数据:

        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:dataPlist options:NSJSONReadingMutableContainers error:&errorJson];

[
{
    "MEMBERID": "xxx",
    "PREFIXINFORMAL": "Mr.",
    "FIRSTNAME": "xxx",
    "MIDDLENAME": "xxxx",
    "LASTNAME": "xxxx",
    "SUFFIX": xxxx
}
]

将此NSDictionary保存到plist的我的代码:

            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *path = [documentsDirectory stringByAppendingPathComponent:@"boardMemberInfo.plist"];
        NSDictionary *test = [NSDictionary dictionaryWithObject:@"test" forKey:@"test"];
        for(NSDictionary *item in json) {
            BOOL success = [item writeToFile:path atomically:YES];
            if(success) {
                NSLog(@"Success Saving New plist");
            } else {
                NSLog(@"Failure Saving New plist");
            }
        }
[item writeToFile…]和[json writeToFile…]都不起作用。但是,简单的[test writeToFile…]可以工作。我错过了什么


谢谢,

您可以做的最好的事情是分解您的保存过程,并使用NSError了解问题所在:

    for(NSDictionary *item in json) {
        NSError *error;
        NSData *serializedData = [NSPropertyListSerialization dataWithPropertyList:item format:… options:… error:&error];
        if (!serializedData) { NSLog(@"Can't serialize data: %@", error); continue; }
        if (![serializedData writeToFile:path options:… error:&error]) {
            NSLog(@"Can't write to %@: %@", path, error);
        } else {
            NSLog(@"Success Saving New plist");
        }
    }

查询返回空值,因此writeToFile失败。我使用decode()sql函数不返回任何null。现在可以了。