NSMutableDictionary 中的转义字符

发布于 2024-11-04 03:17:37 字数 1500 浏览 2 评论 0原文

当我将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-11-11 03:17:37

NSLog 在打印字符串时会对字符串进行转义——您的字符串中可能实际上没有转义字符。

试试这个:

NSLog(@"%s\n", [ string UTF8String ] ) 

看看会发生什么......

NSLog escapes strings when they're printed out--you probably don't actually have escape characters in your string.

Try this:

NSLog(@"%s\n", [ string UTF8String ] ) 

and see what happens...

梅窗月明清似水 2024-11-11 03:17:37

原来是权限问题……是的,尴尬……
让我困惑的是转义字符在响应输出中......

谢谢@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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文