I do know how to do this, it's fairly simple.
The problem is that it doesn't work.
Here's the function I use to POST the data:
- (void)updateWebsitesUsingParameters:(NSDictionary *)parameters;
{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:@"http://notreal/updateWebsites.php"
parameters:parameters
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
//...
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//...
}];
}
Here are the parameters:
NSDictionary *parameters = @{@"type" : @"0",
@"credentials" : @{@"email" : @"[email protected]", @"password" : @"notreal"},
@"device" : @{@"ID" : @"8588107756600540", @"numberOfSessions" : @"0", @"name" : @"Nick's iMac"},
@"websites" : @[@{@"title" : @"Google", @"URL" : @"http://www.google.com"}, @{@"title" : @"Yahoo", @"URL" : @"http://www.yahoo.com"}]};
Here's what gets saved in the MySQL field:
[{URL = "http://www.google.com";},{title = Google;},{URL = "http://www.yahoo.com";},{title = Yahoo;}]
THIS IS CRAZY!
- I have successfully saved JSON of an array of dictionaries with multiple attributes inside a dictionary inside a MySQL field --or in short what I'm trying to do here-- using a PHP script for a different purpose and it works, no problem.
- I use the same PHP code to save it to the MySQL field so IT'S NOT PHP'S FAULT.
- All other save / retrieve functions I have made using AFNetworking work perfectly.
This works:
@[@{@"title" : @"Google"}, @{@"title" : @"Yahoo"}]
This doesn't:
@[@{@"title" : @"Google", @"URL" : @"http://www.google.com"}, @{@"title" : @"Yahoo", @"URL" : @"http://www.yahoo.com"}]
Here's the response:
{
websites = (
{
URL = "http://www.google.com";
},
{
title = Google;
},
{
URL = "http://www.yahoo.com";
},
{
title = Yahoo;
}
);
}
INSANE!
For some reason, it breaks down if I add an extra attribute.
This must be an AFNetworking bug because it makes no sense.
EDIT:
I could:
Make two MySQL fields: websiteTitles, websiteURLs.
Save it as one string: "Google;http://www.google.com" and then separate it but that defeats the purpose of using JSON.
Send the parameters chopped in half: websteTitles, websiteURLs
All are hideous, any ideas?
EDIT 2:
I run a few tests:
It doesn't matter if the array has 1 or 2 items it still behaves like this.
I tried what rob180 suggested and --as expected-- it's AFNetwokring's fault:
{
websites = (
{
URL = "http://www.google.com";
},
{
title = Google;
},
{
URL = "http://www.yahoo.com";
},
{
title = Yahoo;
}
);
}
This is the actual server response of what has been send from the app, no mysql in the middle.
EDIT 3:
REQUEST: <NSMutableURLRequest: 0x7f9352d467e0> { URL: http://notreal/updateWebsites.php }
The HTTPBody looks like this:
<63726564 656e7469 616c735b ... 653d30>
How can I decode this?
Also, I'm using an AFHTTPRequestSerializer. Maybe, if I change it to AFJSONRequestSerializer it will fix the problem but I really don't want to since I have written many methods this way.
operation.request
) – Worden