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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:45:56+00:00 2026-06-02T17:45:56+00:00

I am converting an Array of NSDictionaries to JSON data with the following… Create

  • 0

I am converting an Array of NSDictionaries to JSON data with the following…

Create my data…

NSMutableArray *arrayOfDicts = [[NSMutableArray alloc] init];

for (int i = 0; i < 2; i++) {
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                                  @"MySong", @"title",
                                  @"MyArtist", @"artist",
                                  nil];
    [arrayOfDicts addObject:dict];         
}
 NSArray *info = [NSArray arrayWithArray:arrayOfDicts];
 NSData* jsonData = [NSJSONSerialization dataWithJSONObject:info 
      options:NSJSONWritingPrettyPrinted error:&error];

then send like so…

NSURL *url = [NSURL URLWithString:@"http://www.mywebsite.com/index.php"];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setPostValue:jsonData forKey:@"songs"];
    [request setDelegate:self];
    request.tag = TAG_LOAD_SONGS;
    [request startAsynchronous];

This is sending the NSData to my server, but how do I then use it in php… Its really just a bunch of random numbers if I print it from my server, and I have tried using json_encode but I dont think thats meant for raw data…

Any help would be great!

EDIT:
Here is the Response of php…

echo $_POST['songs'];

<5b0a2020 7b0a2020 20202274 69746c65 22203a20 224d7953 6f6e6722 2c0a2020 20202261 72746973 7422203a 20224d79 41727469 7374220a 20207d2c 0a20207b 0a202020 20227469 746c6522 203a2022 4d79536f 6e67222c 0a202020 20226172 74697374 22203a20 224d7941 72746973 74220a20 207d0a5d>

Here is the response to NSLoging in Xcode…

NSLog(@"Info: %@", info);

Info: (
{
artist = MyArtist;
title = MySong;
},
{
artist = MyArtist;
title = MySong;
}
)

  • 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-02T17:45:58+00:00Added an answer on June 2, 2026 at 5:45 pm

    Turns out I needed to do it like this:

    To Create My data:

    NSMutableArray *arrayOfDicts = [[NSMutableArray alloc] init];
    
    for (int i = 0; i < 2; i++) {
        NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                                      @"MySong", @"title",
                                      @"MyArtist", @"artist",
                                      nil];
        [arrayOfDicts addObject:dict];         
    }
     NSArray *info = [NSArray arrayWithArray:arrayOfDicts];
    

    And Sent it like this:

    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:info 
              options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    
        // Start request
        NSURL *url = [NSURL URLWithString:@"http://www.mywebsite.com/index.php"];
        ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
        [request setPostValue:jsonString forKey:@"songs"];
        [request setDelegate:self];
        [request startAsynchronous];
    

    The key was to convert the info to NSData, then to a JSON String which I sent to my server, not just sending the raw NSData.

    Thanks everyone for the help!

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

Sidebar

Related Questions

I`m having problems converting a char array read from file to an int array.
I have a complicated example of converting a Javascript Array to a JSON String.
Currently, I am reading data from a binary file (File.ReadAllBytes), converting this byte array
I'm wondering if anyone has a recursive solution to converting an array to a
Is there a built-in function for converting a string array into a dictionary of
I have an object which im converting into an array of coords which will
What's the most most ruby-like way of converting from an Array like [:one, 1,
Is converting a file to a byte array the best way to save ANY
Possible Duplicate: Porting a C array declaration to Delphi I'm converting a C code
How would I go about converting a bytearray to a bit array?

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.