Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9120797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:42:17+00:00 2026-06-17T05:42:17+00:00

I am attempting to send a JSON representation of an object in an email

  • 0

I am attempting to send a JSON representation of an object in an email link. The recipient will open the link and my app will respond via a url scheme. It must extract the JSON from the url and re-build the object.

I am serializing my object by building an NSDictionary and using:

return [NSJSONSerialization dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:&error];

I’m not sure what comes next. Somehow I need to convert this NSData into a string so that I can prefix my url scheme and use it in a link.

On the receiving end, I then need to remove the prefix (which I can do) and turn the string back into an NSData.

What is the correct method for doing this? And how do I make sure that the contents of my data do not interfere with the JSON string encoding (e.g. if my object contains text including special characters)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:42:18+00:00Added an answer on June 17, 2026 at 5:42 am

    You need to do an additional encoding step, since there are characters in encoded JSON that also have significance when they are part of a URL. What we actually want to do is URL-encode the data so none of the characters in the resulting string conflict with what applications expect a URL to look like.

    The first step is transforming our data into an NSString (this is basically just a memcpy since NSStrings are encoded in UTF-8 by default):

    NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    

    Now, there’s a function you might be tempted to use called -stringByAddingPercentEscapesUsingEncoding, but it doesn’t do a thorough enough job of escaping all the relevant characters, so we need to build our own.

    I could repeat the code here, but since it’s been done many times already, just view this blog that shows how you can add a category to NSString to do proper encoding, after which you can append it and send it on its way. Writing the analogous decoding function with CFURLCreateStringByReplacingPercentEscapesUsingEncoding is an exercise for the reader of which many examples can be found floating around.

    Make sure your payloads are quite small (on the order of a couple of kB), by the way, since there is probably an upper bound on how long URLs, even those used locally and with a custom scheme, can be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to send a JSON encoded MongoDB object back in my HTTP response.
I am attempting to send some data via JSON to a MVC controller action:
I am attempting to create json data to send to a server via an
I am attempting to send a json message from a custom application to a
I'm attempting to write a Python function to send an email to a list
I am attempting to use JSON to send data between the browser and my
I'm attempting to send emails from my C# app using the System.Net.Mail.MailMessage class. For
I have the following code which is attempting to send an email in background.
I am attempting to send a message via sockets from VBA. I have made
im attempting to send an email to the active user when an event is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.