0

嗨,我这里有这段代码。

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];

            }

我想要做的是得到服务器在 NSJon 中给出的响应。我正在尝试捕捉下面的内容。我尝试使用 NSMutableArray 来获取它,但它没有用。我究竟做错了什么?

{"status":1}
4

1 回答 1

0

问题是 NSJSONSerialization 用 NSDictionary 回答,而不是 NSMutableArray。你不能强迫它成为一个数组,因为它需要一个值和一个键(在这种情况下,键是“状态”,值是“1”)

于 2012-06-14T22:53:16.127 回答