Capturing PHP Response Through NSJSONSerialization

Hi I have this code here.

NSString *name = [[NSString alloc] initWithFormat:[nameField text]];
        NSString *street = [[NSString alloc] initWithFormat:[streetField text]];
        NSString *city = [[NSString alloc] initWithFormat:[cityField text]];
        NSString *state = [[NSString alloc] initWithFormat:[stateField text]];
        NSString *zip = [[NSString alloc] initWithFormat:[zipField text]];
        NSString *urlToAuthPage = [[NSString alloc] initWithFormat:@"&name=%@&street=%@&city=%@&state=%@&zip=%@&lat=%@&lon=%@", name, street, city, state, zip, str1, str2];

        NSData *postData = [urlToAuthPage dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
        NSString *postLength = [NSString stringWithFormat:@"%d",[urlToAuthPage length]];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://yourlink.com/poop.php"]]];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:postData];
        NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];

        NSError *error;
        NSMutableArray *infoArray = (NSMutableArray*)[NSJSONSerialization JSONObjectWithData:postData options:kNilOptions error:&error];
        NSLog(@"%@", [infoArray objectAtIndex:0]);

       if (conn) {
            UIAlertView *successAlert = [[UIAlertView alloc] initWithTitle:@"Success!" message:@"Your party has been successfully posted" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles: nil];
            [successAlert show];
            //NSLog(conn);

            nameField.text = @"";
            streetField.text = @"";
            cityField.text = @"";
            stateField.text = @"";
            zipField.text = @"";

            [nameField resignFirstResponder];
            [streetField resignFirstResponder];
            [cityField resignFirstResponder];
            [stateField resignFirstResponder];
            [zipField resignFirstResponder];

            }

What I'm trying to do is get the response the server gives out that is in NSJon. I'm trying capture what is below. I've tried using an NSMutableArray to get it but it didn't work. What am I doing wrong?

{"status":1}

Answers


The problem is that NSJSONSerialization answers witha NSDictionary, not an NSMutableArray. You can't force it to be an array, since it needs a value and a key (in this case the key is "status" and the value is "1")


Need Your Help

Rails 3 + Heroku: Find out dyno's memory usage

ruby-on-rails-3 heroku

Is there any way to find out how much memory a heroku web dyno is using? Let's say I wanna write a rake task that runs periodically and checks every dyno's memory usage. How could I do this? Thanks!

Deterministic builds under Windows

c++ windows visual-c++ portable-executable

The ultimate goal is comparing 2 binaries built from exact same source in exact same environment and being able to tell that they indeed are functionally equivalent.