【发布时间】:2015-02-01 16:50:31
【问题描述】:
我正在尝试创建如下所示的 JSON:
{
"id": "feed/http://feeds.feedburner.com/design-milk",
"title": "Design Milk",
"categories": [
{
"id": "user/category/test",
"label": "test"
}
]
}
我是用这个方法做的:
NSMutableDictionary *req = [NSMutableDictionary @"feed/http://feeds.feedburner.com/design-milk" forKey:@"id"];
[req @"Design Milk" forKey:@"title"];
NSDictionary *tmp = [[NSDictionary alloc] initWithObjectsAndKeys:
@"user/category/test", @"id", @"test", @"label",
nil];
[req setObject:tmp forKey:@"categories"];
NSData *postdata = [NSJSONSerialization dataWithJSONObject:req options:0 error:&error];
但是,这不起作用。我在这里做错了什么?
【问题讨论】:
-
访问 json.org 并学习 JSON 语法。学习只需5-10分钟。然后你会意识到你缺少一个 JSON 数组。
标签: objective-c json nsdictionary