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

The Archive Base Latest Questions

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

I am trying to send to my server a json file. The json format

  • 0

I am trying to send to my server a json file. The json format should look exactly like this:

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

I hardcoded this and worked like this:

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

So i want to do the exact same thing but using an NSDictionary cause of course i dont want to hardcode all my data.
So i am creating an NSDictionary like this:

NSMutableDictionary *eventLocation = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"43.93838383",@"latitude",@"-3.46", @"longitude" , nil];

    NSMutableDictionary *eventData = [NSMutableDictionary dictionaryWithObjectsAndKeys:eventLocation,@"eventLocation", nil];
                        [eventData setObject:@"Jun 13, 2012 12:00:00 AM" forKey:@"eventDate"];
                        [eventData setObject:@"hjhj" forKey:@"text"];
                        [eventData setObject:@"raw data" forKey:@"imageData"];
                        [eventData setObject:@"JPEG" forKey:@"imageFormat"];
                        [eventData setObject:@"1339538400000" forKey:@"expirationTime"];

    NSMutableDictionary *finalDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:eventData,@"eventData", nil];
                        [finalDictionary setObject:@"ELDIARIOMONTANES" forKey:@"type"];
                        [finalDictionary setObject:@"accIDENTE" forKey:@"title"];

Now i have to convert this to the correct json format , so that i can send it to my server.
I tried using this :

NSError *error;
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:finalDictionary 
                                                           options:NSJSONWritingPrettyPrinted
                                                             error:&error]

but now when i print the jsonData i get this :

jsonData: <7b0a2020 22657665 6e744461 74612220 3a207b0a 20202020 22696d61 6765466f 726d6174 22203a20 224a5045 47222c0a 20202020 22746578 7422203a 2022686a 686a222c 0a202020 2022696d 61676544 61746122 203a2022 72617720 64617461 222c0a20 20202022 65787069 72617469 6f6e5469 6d652220 3a202231 33333935 33383430 30303030 222c0a20 20202022 6576656e 744c6f63 6174696f 6e22203a 207b0a20 20202020 20226c6f 6e676974 75646522 203a2022 2d332e34 36222c0a 20202020 2020226c 61746974 75646522 203a2022 34332e39 33383338 33383322 0a202020 207d2c0a 20202020 22657665 6e744461 74652220 3a20224a 756e2031 332c2032 30313220 31323a30 303a3030 20414d22 0a20207d 2c0a2020 22747970 6522203a 2022454c 44494152 494f4d4f 4e54414e 4553222c 0a202022 7469746c 6522203a 20226163 63494445 4e544522 0a7d>

What is this exactly?? How can i just convert that dictionary to look exactly like this:

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

If possible i want the above format to be an NSString cause that was what i was sending to the server and it was working. I mean an NSString , in json format like this.
Thank you very much for bothering reading all this! 😀

  • 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:01:11+00:00Added an answer on June 6, 2026 at 4:01 pm

    Your conversion is fine, NSData looks like that because it’s a bunch of bytes!

    You need to convert it to string, try this:

    NSString* aStr;
    aStr = [[NSString alloc] initWithData:aData encoding:NSUTF8StringEncoding];
    

    The method:

    + (NSData *)dataWithJSONObject:(id)obj options:(NSJSONWritingOptions)opt error:(NSError **)error
    

    Returns a NSData object, NSData is just an object wrapper for a byte representation, so your dictionary is there, but in the form of a byte representation.

    Then you use:

    - (instancetype)initWithData:(NSData *)data encoding:(NSStringEncoding)encoding
    

    This method takes your byte representation and turn it into a string, using the encoding that you provide.

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

Sidebar

Related Questions

I've been trying to send a JSON string to PHP server like this: $.ajax({
I'm trying to send a File to the Server without success. I have this
I am trying to send an array of this struct to a DBus Server:
I am trying to send a JSON string to the server and retrieve back
I'm trying to send JSON data to a server. RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
I'm trying to send json string in the get request to the server, here
I am trying to send data, in json format to my webservice, using POST.
I am trying to send JSON to my server and retrieve a JSON in
I am trying to send JSON data to a web server via the code
I'm trying to send a broadcast and then let the server reply to it:

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.