Note that there are some explanatory texts on larger screens.

plurals
  1. POEncode JSON data for URL
    primarykey
    data
    text
    <p>In iOS, I want to send JSON data in URL to make service call. I tried following code snipped but Encoded URL seems wrong. Because in JSON there is a colon character (:) between key and value and comma character (,) for separation. But, i am not able to encode colon(:) as <strong>%3A</strong> and comma(,) as <strong>%2C</strong></p> <p><strong>Code Snippet:</strong></p> <pre><code>- (NSURL *)getEncodedUrl { // Build dictionnary with parameters NSString *abc = @"abc"; NSNumber *limitNumber = [NSNumber numberWithInt:2]; NSMutableDictionary *dictionnary = [NSMutableDictionary dictionary]; [dictionnary setObject:limitNumber forKey:@"limit"]; [dictionnary setObject:abc forKey:@"abc"]; NSError *error; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionnary options:0 error:&amp;error]; if (!jsonData) { debug("Json error %@",error); return nil; } else { NSString *JSONString = [[NSString alloc] initWithBytes:[jsonData bytes] length:[jsonData length] encoding:NSUTF8StringEncoding]; debug("Json op %@",JSONString); NSString* params = [JSONString stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding]; NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://baseUrl.com?param=@",params]]; debug("URL = %@",url); return url; } } </code></pre> <p><strong>OUTPUT:~</strong></p> <p>URL = <a href="http://baseUrl.com?param=%7B%22abc%22:%22abc%22,%22limit%22:2%7D" rel="nofollow">http://baseUrl.com?param=%7B%22abc%22:%22abc%22,%22limit%22:2%7D</a></p> <p>(Include colon and comma characters)</p> <p>But I want following o/p:</p> <p><strong><a href="http://baseUrl.com?param=%7B%22abc%22%3A%22abc%22%2C%22limit%22%3A2%7D" rel="nofollow">http://baseUrl.com?param=%7B%22abc%22%3A%22abc%22%2C%22limit%22%3A2%7D</a></strong></p> <p>(No colon and comma characters)</p> <p>Online Encoding-Decoding Site that I am referring as of now. </p> <p><a href="http://www.url-encode-decode.com/" rel="nofollow">http://www.url-encode-decode.com/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload