所以我有一个 NSMutableArray 需要保存到文件的对象。用方法保存它writeToFile
不起作用,因为我有 NSNull 值,这些值在此方法生成的 .plist 格式中是不允许的。
所以我通过将文件保存为 NSString 来将文件保存到磁盘:
NSString *content = [NSString stringWithFormat:@"%@",orders];
[content writeToFile:ordersFilePath atomically:NO];
这会生成一个像这样的文件:
(
{
ZBILLINGADDRESS1 = "";
ZBILLINGADDRESS2 = "";
ZBILLINGCITY = "";
ZBILLINGCOUNTRY = "";
ZBILLINGSTATE = "";
ZBILLINGZIP = "";
ZCANCELDATE = "<null>";
ZCATALOGCODE = "";
ZCATALOGNAME = "";
ZCONTACTEMAIL = "";
ZCONTACTFAX = "";
ZCONTACTNAME = " ";
ZCONTACTPHONE = "";
ZCONTAINERCUBES = 0;
ZCONTAINERNAME = "";
ZCURRENCYCODE = "<null>";
ZCUSTOMERID = 0;
ZCUSTOMERNAME = "Dupe offline Test";
ZCUSTOMERNUMBER = 1297145;
ZDISCOUNT = 0;
ZDONOTSHIPBEFORE = "<null>";
ZEXPORTDATE = "-63113886238";
ZEXPORTED = 1;
ZFOB = "";
ZFREIGHTTERM = "";
ZISCONTAINER = 0;
ZISDEFAULT = 0;
ZISDELETED = 0;
ZISPLACED = 0;
ZMANUFACTURERID = 18;
ZMARKETNAME = "";
ZNOTES = "last second note";
ZORDERDATE = 372571200;
ZORDERGUID = "5650d30a-9316-436a-87e9-1e0ead3af8d7";
ZORDERID = 84340;
ZORDERSTATUS = Accept;
ZORDERTOTAL = 200;
ZORDERTYPE = "";
ZORIGIN = "";
ZPONUMBER = 3;
ZPRICELEVEL = 2;
ZREPNUMBER = 1;
ZSALESREPID = 235;
ZSHIPDATE = 373176000;
ZSHIPPINGTOTAL = 0;
ZSHIPTOADDRESS1 = "";
ZSHIPTOADDRESS2 = "";
ZSHIPTOCITY = "";
ZSHIPTOCOMPANYNAME = "";
ZSHIPTOCONTACTEMAIL = "";
ZSHIPTOCONTACTNAME = "";
ZSHIPTOCONTACTPHONE = "";
ZSHIPTOCOUNTRY = "";
ZSHIPTOFAX = "";
ZSHIPTOSTATE = "";
ZSHIPTOZIP = "";
ZSHIPVIA = "";
ZSOURCE = ipad;
ZSUBTOTAL = 200;
ZTAXRATE = 0;
ZTAXTOTAL = 0;
ZTERMS = "";
ZWRITTENBYNAME = "";
ZWRITTENFORNAME = "";
ZWRITTENFORREPNUMBER = "";
ZWRITTENFORREPNUMBER1 = "<null>";
"Z_ENT" = 17;
"Z_OPT" = 5;
"Z_PK" = 450;
}
)
问题是当我尝试将其重新加载为 NSArray 时,我得到一个空值:
NSString *str = [NSString stringWithContentsOfFile:ordersFilePath encoding:NSUTF8StringEncoding error:NULL];
NSArray *loadedOrders = [[NSArray alloc] initWithContentsOfFile:str];
我在这里想念什么?