2010-10-12 51 views
1

我有一个JSON返回,我试图保存到一个NSDictionary,但是,由于在返回的数据中有空格,字典不会保存这个数组,因为引用被包含在内。有没有办法解析SBJSON删除双引号保存到rowsArray之前?我需要从JSON删除双引号在NSDictionary中使用

rowsArray: { 
Rows =  (
      { 
     Children =    (
          { 
       Title = Chevy; 
      }, 
          { 
       Title = "Red Color"; 
      }, 
          { 
       Title = "Pre - 1965"; 
      }, 
          { 
       Title = "White Walls"; 
      },   
     ); 
     Title = Chevy; 
    }, 

下面是代码 // JSON NSURL请求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]; 

这个伟大的工程,节省如果字符串,其中雪佛兰,但如果双引号在那里的.plist韩元“T保存

感谢,

迈克尔

回答

0

删除所有报价的最简单方法是使用:

-[NSString stringByReplacingOccurrencesOfString: withString:]

像这样:

NSString *cleanedString=[jsonreturn stringByReplacingOccurrencesOfString:@"/"" withString:@""]; 

的“/”是加引号的转义字符。