【发布时间】:2010-10-12 15:52:08
【问题描述】:
我有一个 JSON 返回,我试图将它保存到 NSDictionary 中,但是,由于返回的数据中有空格,因此 Dictionary 不会保存这个数组,因为包含了引号。有没有办法在保存到 rowsArray 之前解析 SBJSON 以删除双引号?
rowsArray: {
Rows = (
{
Children = (
{
Title = Chevy;
},
{
Title = "Red Color";
},
{
Title = "Pre - 1965";
},
{
Title = "White Walls";
},
);
Title = Chevy;
},
这里是代码 //JSON NSURL REQUEST for rowsArray
NSURL *url = [NSURL URLWithString:@"http://www.**.php"];
NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url ]
SBJSON *json = [[SBJSON alloc] init];
NSError *error = nil;
rowsArray= [json objectWithString:jsonreturn error:&error];
NSLog(@"rowsArray: %@",rowsArray);
//SAVING rowsArray as "FollowingArray.plist"
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path2 = [documentsDirectory stringByAppendingPathComponent:@"FollowingArray.plist"];
[rowsArray writeToFile:path2 atomically:NO];
[jsonreturn release];
[json release];
这很好用,如果 Chevy 所在的字符串可以保存,但如果双引号在其中,.plist 将不会保存
谢谢,
迈克尔
【问题讨论】:
标签: php iphone json nsarray nsdictionary