原来我需要这样做:
要创建我的数据:
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:infooptions: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];
关键是将信息转换为
NSData,然后转换为我发送到服务器的JSON字符串,而不仅仅是发送raw
NSData。
谢谢大家的帮助!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)