应用程序崩溃后发送json对象

时间:2011-11-07 10:21:11

标签: iphone objective-c ios nsurlconnection

enter image description here

您好, 我正在尝试使用以下示例代码发送带有NSUrlconnection的json对象... 应用程序在到达最后一行后崩溃:[[NSURLConnection alloc] initWithRequest:request delegate:self];

任何想法?

2 个答案:

答案 0 :(得分:3)

- (void)setHTTPBody:(NSData *)data

需要NSData *才能工作

尝试:

NSData *requestdata = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:requestData];

答案 1 :(得分:0)

+ (id)dataWithBytes:(const void *)bytes length:(NSUInteger)length   

bytes:
A buffer containing data for the new object.
length:
The number of bytes to copy from bytes. This value must not exceed the length of bytes.

第一个参数不是NSString,而是提供NSString