ios - iPhone 如何使用 json 发布 nsarry

标签 ios iphone json post ios5

我有很多 json 对象,例如:

{"id":"1","list":"456","name":"a"}, {"id":"2","list":"456","name":"b"}, {"id":"3","list":"456","name":"c"}

它们存储在 NSDictionary dic1, dic2, dic3 中,然后我使用 NSArray 存储这些 dic,

这是我的问题,我如何发布这些词典?

我知道发布一个 json 对象,这是我的代码

NSString *url = [SERVERPREFIX stringByAppendingString:urlString];
DLog(@"url:%@", url);
NSURL *reqURL = [NSURL URLWithString:url];
NSData ***__jsonData**;
// Be sure to properly escape your url string.
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:reqURL];
[request setHTTPMethod:@"POST"];
[request setHTTPBody: **__jsonData**];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

[request setValue:[NSString stringWithFormat:@"%d", (unsigned int)[__jsonData length]] forHTTPHeaderField:@"Content-Length"];


[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {

那么,问题是 __jsonData 应该是什么?

最佳答案

jsonData 应该是:

jsonData = [NSJSONSerialization dataWithJSONObject:yourNSArray options:NSJSONWritingPrettyPrinted error:&error];

关于ios - iPhone 如何使用 json 发布 nsarry,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20878508/

相关文章:

iphone - 如何在 iPhone 中使用 URL 链接播放音乐文件?

javascript - 自动完成 json 数据

java - OneToMany 将 POJO 映射到 JSON Spring

ios - RestKit 0.20 映射问题(使用来自 API 的 JSON)

ios - 在 Swift2 中获取不带扩展名的文件名的重大更改

iphone - IOS 中是否存在用于 UI 控件自动化的现有库

Play 2.4 中特征的 Json 格式化程序

ios - ios swift 无法从 UIDocumentPickerViewController 获取 .doc 文件

ios - 从 MasterView 触发 DetailView 中的弹出窗口

iphone - 如何在 CoreData 应用程序中使用默认数据初始化存储?