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 8154859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:29:42+00:00 2026-06-06T16:29:42+00:00

Ok i need to use json on my iOS application to send/receive data to/from

  • 0

Ok i need to use json on my iOS application to send/receive data to/from my server. The problem is i got a bit confused about how the json file should look like.
I need the json file that i am sending to the server to look like this :

NSString *jsonString = @"{\"eventData\":{\"eventDate\":\"Jun 13, 2012 12:00:00 AM\",\"eventLocation\":{\"latitude\":43.93838383,\"longitude\":-3.46},\"text\":\"lalalala\",\"imageData\":\"raw data\",\"imageFormat\":\"JPEG\",\"expirationTime\":1339538400000},\"type\":\"ELDIARIOMONTANES\",\"title\":\"accIDENTE\"}";

When i try to print this in the console i get :

jsonString: {"eventData":{"eventDate":"Jun 13, 2012 12:00:00 AM","eventLocation":{"latitude":43.93838383,"longitude":-3.46},"text":"lalalala","imageData":"raw data","imageFormat":"JPEG","expirationTime":1339538400000},"type":"ELDIARIOMONTANES","title":"accIDENTE"}

which according to online json validators seems to be a valid json format.

HOWEVER , after searching the web , and of course stackoverflow , and after have asked another question about this , i found out that i should convert the above NSString to a json file like this :

NSString *jsonString = @"{\"eventData\":{\"eventDate\":\"Jun 13, 2012 12:00:00 AM\",\"eventLocation\":{\"latitude\":43.93838383,\"longitude\":-3.46},\"text\":\"lalalala\",\"imageData\":\"raw data\",\"imageFormat\":\"JPEG\",\"expirationTime\":1339538400000},\"type\":\"ELDIARIOMONTANES\",\"title\":\"accIDENTE\"}";

    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *e;
    NSMutableArray *jsonList = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&e];

But if i try to print the jsonList variable , which i thought it would be the json format/file i get this :

jsonList: {
    eventData =     {
        eventDate = "Jun 13, 2012 12:00:00 AM";
        eventLocation =         {
            latitude = "43.93838383";
            longitude = "-3.46";
        };
        expirationTime = 1339538400000;
        imageData = "raw data";
        imageFormat = JPEG;
        text = lalalala;
    };
    title = accIDENTE;
    type = ELDIARIOMONTANES;
}

which is not a valid json file!!!! So my question is , if i had from the very beginning the correct format to my json file why all this extra code to “convert” it to json?? I guess , i MUST be missing something here or misunderstood the functionality of the code.
Thank you very much for reading my post 🙂

  • 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-06T16:29:44+00:00Added an answer on June 6, 2026 at 4:29 pm

    I think you’re getting yourself tied up in knots there a little bit 🙂 If you have a NSString containing exactly the data you wish to send, there’s no point using JSONObjectWithData et al, you might as well just send the string you have already.

    However, if you want to extract bits of data you’re receiving as JSON from the server, that’s when you’d create want to use those methods. It’s much easier and more reliable to get data out of a parsed JSON object that just a big old plain JSON string (regex’ing is not a good way to extract data from JSON).

    The other case is where you want to build up a large and complex JSON object in code, and then send that as a JSON string to your server. You don’t want to try this by appending NSStrings together (gets nasty quickly) it’s better to put your data is NSMutableArrays or NSDictionaries and then convert to JSON.

    Here’s a quick example of this ( from here )

    NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:@"test@test.com", @"user",@"mypass", @"pass", nil];
    
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:NSJSONWritingPrettyPrinted error:&writeError];
    
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSLog(@"JSON Output: %@", jsonString);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Do I need to use JSON to transfer data from external PHP server to
For an iPhone application I need to request data from an online database. I
I'm building and iOS application which fetches data from my MYSQL database, so to
I am confused about how to use json in my rails (2.3.5) app. These
I am develop a iPhone application, in which i need to use JSON to
Possible Duplicate: JSON Parsing in Android As I find out I need to use
I need to create a custom json for the jit library. Should I use
I need a tool which generates random JSON objects. I want to use this
I'm desperately trying to use json data to fill my dojo spider chart. First
I am developing an android application in eclipse that needs to use JSON, Google

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.