NSString *profilestring = [self.userDefaults objectForKey:@"profilestrings"];
NSDictionary *dicProfile = [profilestring propertyListFromStringsFileFormat];
NSLog(@"--->>%@",profilestring);
NSLog(@">>%@",dicProfile);
self.userDefaults
是NSUserDefaults,NSLog(@"--->>%@",profilestring);
打印一个字符串,例如
{
useraddtime = 1401444211;
userage = 11;
usernickname = XJD;
usersex = 1;
userstatus = 1;
}
但NSLog(@">>%@",dicProfile);
打印(null)
,你能帮助我吗?
答案 0 :(得分:1)
Apples文档说键和值本身总是用直引号括起来的字符串。您的密钥和值未包含在引号中。字符串即profilestring应如下所示
{
"useraddtime" = "1401444211";
"userage" = "11";
"usernickname" = "XJD";
"usersex" = "1";
"userstatus" = "1";
}
答案 1 :(得分:0)
您的[self.userDefaults objectForKey:@"profilestrings"]
实际上是NSDictionary
,因此您可以执行类似
NSDictionary *dicProfile = [NSDictionary dictionaryWithDictionary:[self.userDefaults objectForKey:@"profilestrings"]];