2012-11-16 51 views
2

含有新行字符解析JSON数据I具有在IOS应用中的问题分析包含新行字符JSON数据(\n等)。我使用XCode 4.3。我添加了用于解析JSON的代码;应用程序在找到新的行字符时会崩溃。如何更换或处理换行字符的JSON数据解析器或NSString更换呢?在iPhone应用程序

NSString *jsonData = @"[{ "department": "","email_address1":"[email protected]"}]";  
jsonData = [jsonData stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]]; 
NSError *e = nil; 
NSData *projNSdata = [jsonData dataUsingEncoding:NSUTF8StringEncoding]; 
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData: projNSdata options: NSJSONReadingMutableContainers error: &e]; 

回答

1

入住这modifiedjsonDatastring它完美的工作。由于problemjsonstring

NSString *jsonData = @"[{\n \"department\": \"\",\"email_address1\":\"[email protected]\"}]"; 

Replace mine with yours

Error是在双引号没有值:

NSLog(@"Json : %@ \n Error :%@",jsonArray,[e description]); 

NSString *jsonData = @"[{ "department": "","email_address1":"[email protected]"}]"; 
             here 

而且在最后添加下面线