NSMutableDictionary 中的转义字符
当我将 NSString 作为 NSMutableDictionary 中的键的对象传递时,它似乎包含转义字符作为常规字符。我怎样才能删除它们?我尝试过 stringByReplacingOccurrencesOfString:@"\" withString:@"" 但它不起作用。
这是我的代码和输出:
代码:
NSString* fql1 = [NSString stringWithFormat:@"SELECT page_id FROM place WHERE distance(latitude,longitude,\"%@\",\"%@\") < 1500 AND checkin_count > 5", latitude, longitude];
NSString* fql2 = [NSString stringWithFormat:@"SELECT author_uid, post_id, timestamp, tagged_uids, message FROM checkin WHERE page_id IN (select page_id from #PlaceQuery)"];
NSString* fql = [[NSString stringWithFormat:@"{\"PlaceQuery\":\"%@\",\"CheckInQuery\":\"%@\"}",fql1,fql2] stringByReplacingOccurrencesOfString:@"\\" withString:@""];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObject:fql forKey:@"queries"];
NSLog(@"%@", fql);
NSLog(@"%@", params);
NSLog(@"%@", fql) 的输出:
{"PlaceQuery":"从地点中选择 page_id,其中距离(纬度,经度,"37.331693","-122.030457") < 1500 AND checkin_count > 5","CheckInQuery":"选择author_uid, post_id, 时间戳、tagged_uids、消息来自签入 WHERE page_id IN(从 #PlaceQuery 选择 page_id)”}
NSLog 的输出(@"%@", params):
{ 查询 = "{\"PlaceQuery\":\"从地点选择 page_id WHERE 距离(纬度,经度,\"37.331693\",\"-122.030457\") <第1500章5\",\"CheckInQuery\":\"SELECTauthor_uid, post_id, timestamp, tagged_uids, message FROM checkin WHERE page_id IN (select page_id from #PlaceQuery)\"}"; }
所以提前非常感谢;)
When i pass an NSString as object for a key in an NSMutableDictionary it seems to contain escape characters as regular characters. How can I remove them? I have tried stringByReplacingOccurrencesOfString:@"\" withString:@"" byt it does not work.
Here is my code and output:
Code:
NSString* fql1 = [NSString stringWithFormat:@"SELECT page_id FROM place WHERE distance(latitude,longitude,\"%@\",\"%@\") < 1500 AND checkin_count > 5", latitude, longitude];
NSString* fql2 = [NSString stringWithFormat:@"SELECT author_uid, post_id, timestamp, tagged_uids, message FROM checkin WHERE page_id IN (select page_id from #PlaceQuery)"];
NSString* fql = [[NSString stringWithFormat:@"{\"PlaceQuery\":\"%@\",\"CheckInQuery\":\"%@\"}",fql1,fql2] stringByReplacingOccurrencesOfString:@"\\" withString:@""];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObject:fql forKey:@"queries"];
NSLog(@"%@", fql);
NSLog(@"%@", params);
Output from NSLog(@"%@", fql):
{"PlaceQuery":"SELECT page_id FROM place WHERE distance(latitude,longitude,"37.331693","-122.030457") < 1500 AND checkin_count > 5","CheckInQuery":"SELECT author_uid, post_id, timestamp, tagged_uids, message FROM checkin WHERE page_id IN (select page_id from #PlaceQuery)"}
Output from NSLog(@"%@", params):
{
queries = "{\"PlaceQuery\":\"SELECT page_id FROM place WHERE distance(latitude,longitude,\"37.331693\",\"-122.030457\") < 1500 AND checkin_count > 5\",\"CheckInQuery\":\"SELECT author_uid, post_id, timestamp, tagged_uids, message FROM checkin WHERE page_id IN (select page_id from #PlaceQuery)\"}";
}
I have been searching for hours for a solution so thanks A LOT in advance ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NSLog 在打印字符串时会对字符串进行转义——您的字符串中可能实际上没有转义字符。
试试这个:
看看会发生什么......
NSLog escapes strings when they're printed out--you probably don't actually have escape characters in your string.
Try this:
and see what happens...
原来是权限问题……是的,尴尬……
让我困惑的是转义字符在响应输出中......
谢谢@williham 和@nielsbot
This turned out to be an issue about permissions... yes, embarrasing...
What confused me was that the escape characters was in the response output...
Thanks @williham and @nielsbot