json PUT 请求
我正在发送 JSON PUT 请求。我正在使用 JSONKIT。我不确定如何将字典转换为 JSON 数据?
我想要一个与 JSONKIT 中的 JSONREPRESNTATION(JSON parser) 等效的方法。示例代码如下。
NSMutableDictionary *jsonDict = [[NSMutableDictionary alloc] initWithCapacity:0];
[jsonDict setObject:@"linkedin-html" forKey:@"contentType"];
[jsonDict setObject:@"dfdfdf" forKey:@"body"];
NSString *jsonRequest = [jsonDict JSONData]; // doubt line
NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]];
[self setHTTPBody:requestData];
[self setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
[self setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
I'm sending JSON PUT request. I'm using JSONKIT. I'm not sure about how to convert dictionary to JSON data?
I want a equivalent method to JSONREPRESNTATION(JSON parser) in JSONKIT. sample code is as follows.
NSMutableDictionary *jsonDict = [[NSMutableDictionary alloc] initWithCapacity:0];
[jsonDict setObject:@"linkedin-html" forKey:@"contentType"];
[jsonDict setObject:@"dfdfdf" forKey:@"body"];
NSString *jsonRequest = [jsonDict JSONData]; // doubt line
NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]];
[self setHTTPBody:requestData];
[self setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
[self setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
id json = [arrayOne JSONString];
位于 https://github.com/johnezang/JSONKit/blob/master/自述文件.md
id json = [arrayOne JSONString];
Available at, https://github.com/johnezang/JSONKit/blob/master/README.md