我正在使用一个http服务器,它在响应正文中返回JSON字符串:
"Some text.\nSome text.\n\t\"Some text in quotes.\""
Run Code Online (Sandbox Code Playgroud)
我需要在字符串的开头和结尾删除引号,我需要unescape特殊符号.我为NSString制作类别,但我认为这是错误的实现:https://gist.github.com/virasio/59907e087f859e6c1723 我有其他想法.我可以使用NSJSONSerialization:
NSString *sourceString = @"\"Some text.\\nSome text.\\n\\t\\\"Some text in quotes.\\\"\"";
NSString *jsonObject = [NSString stringWithFormat:@"{ \"value\" : %@ }", sourceString];
NSDictionary *object = [NSJSONSerialization JSONObjectWithData:[jsonObject dataUsingEncoding:NSUTF8StringEncoding options:0 error:NULL]];
NSString *result = [object objectForKey:@"value"];
Run Code Online (Sandbox Code Playgroud)
但是......它也不好.