我需要从 JSON 中删除双引号以便在 NSDictionary 中使用
我有一个 JSON 返回,我试图将其保存到 NSDictionary 中,但是,由于返回的数据中有空格,字典不会保存此数组,因为包含引号。有没有办法在保存到 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];
这很好用,如果雪佛兰所在的字符串可以保存,但如果双引号在那里,.plist 将不会保存
谢谢,
迈克尔
I have a JSON return that I'm trying to save into a NSDictionary, However, Since there are spaces in the data being returned, the Dictionary won't save this array because of the quote being included. Is there a way to parse the SBJSON to remove the double quotes prior to saving to the rowsArray?
rowsArray: {
Rows = (
{
Children = (
{
Title = Chevy;
},
{
Title = "Red Color";
},
{
Title = "Pre - 1965";
},
{
Title = "White Walls";
},
);
Title = Chevy;
},
Here is the code
//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];
This works Great and saves if the string where Chevy is, but if the double quotes are in there the .plist won't save
Thanks,
Michael
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除所有引号的最简单方法是使用:
-[NSString stringByReplacingOccurrencesOfString: withString:]
如下所示:
“/”是引号的转义字符。
The easiest way to remove all the quotes would be to use:
-[NSString stringByReplacingOccurrencesOfString: withString:]
like so:
the "/" is the escape character for the quotes.