相关疑难解决方法(0)

JSON:为什么正斜线逃脱了?

这个"逃脱"我的原因.

JSON转义正斜杠,因此哈希{a: "a/b/c"}被序列化为{"a":"a\/b\/c"}而不是{"a":"a/b/c"}.

为什么?

javascript json

354
推荐指数
5
解决办法
17万
查看次数

如何防止NSJSONSerialization在URL中添加额外的转义

如何防止NSJSONSerialization在我的URL字符串中添加额外的反斜杠?

NSDictionary *info = @{@"myURL":@"http://www.example.com/test"};
NSData data = [NSJSONSerialization dataWithJSONObject:info options:0 error:NULL];
NSString *string = [[NSString alloc] initWithData:policyData encoding:NSUTF8StringEncoding];
NSLog(@"%@", string);//{"myURL":"http:\/\/www.example.com\/test"}
Run Code Online (Sandbox Code Playgroud)

我可以去除反斜杠并使用该字符串,但如果可能的话我想跳过这一步......

objective-c nsjsonserialization

26
推荐指数
3
解决办法
1万
查看次数

AFNetworking序列化正斜杠,使JSON有效负载无效

我正在使用AFNetworking2.0.

AFNetworking,AFHTTPRequestOperationManager对象有一个API:

(AFHTTPRequestOperation *)POST:(NSString *)URLString
                    parameters:(id)parameters
                       success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
Run Code Online (Sandbox Code Playgroud)

它接受NSDictionary作为我们希望"POST"到服务器的JSON Payload的params.在我的有效载荷中,我有以下键值对:

"buttonActionParam":"/catalog/special/international-calling"

发布此有效内容服务器会返回无效的JSON.查看服务器端的有效负载,我意识到AFNetworking实际上正在发送:

"buttonActionParam":"\/catalog\/special\/international-calling".

我知道AFNetworking库使用NSJSONSerialization的是类方法-dataWithJSONObject:,这会导致这种情况.我的问题是:

问:如何解决这个问题?

json objective-c ios afnetworking-2

9
推荐指数
1
解决办法
7605
查看次数