问题描述
- 在JSON中如何让数组正常显示
- 我要在JSON中发送数组
代码如下:
-(void)getConnection { NSArray *comment=[NSArray arrayWithObjects:@""aaa""@""bbb""@""ccc""@""helloyestell"" nil]; NSURL *aurl=[NSURL URLWithString:@""http://sajalaya.com/taskblazer/staffend/form/iphonearraytest.php""]; NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:aurl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; [request setValue:@""application/x-www-form-urlencoded"" forHTTPHeaderField:@""Content-Type""]; [request setHTTPMethod:@""POST""]; NSData *jsonData2 = [NSJSONSerialization dataWithJSONObject:comment options:NSJSONWritingPrettyPrinted error:nil]; NSString *new = [[NSString alloc] initWithData:jsonData2 encoding:NSUTF8StringEncoding]; // NSString *new = [comment JSONString]; // NSArray *new=[comment jsonvalue]; NSString *postString=[NSString stringWithFormat:@""tag=&comment=%@&total=%@""new@""4""]; NSLog(@""this is post string%@""postString); [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]]; [NSURLConnection connectionWithRequest:request delegate:self]; }
时间: 2024-10-03 17:48:24