0
我有一個與Json刪除方法。我在互聯網上衝浪,什麼都沒有。目標C中的JSON DELETE方法不起作用?
這裏是我嘗試過的Json刪除方法的代碼。它只是返回 「的Json值失敗」
NSString *posturl=[NSString stringWithFormat:@"%@/spottings/%@/media/%@.json?auth_token=%@",_BASE_API_URL,[_spotting_id_array objectAtIndex:button.tag],[_ex_media_id_array objectAtIndex:button.tag],_ex_auth_token_str];
NSLog(@"posturl:%@",posturl);
// Prepare string request
NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"%@",posturl]];
// Prepare URL request
NSMutableURLRequest *request =[[[NSMutableURLRequest alloc] init] autorelease];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
// Set the URL to request
[request setURL:url];
// Set the URL method
[request setHTTPMethod:@"DELETE"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *urlData, NSError *error){
if ([urlData length] >0 && error == nil)
{
// Get JSON as a NSString from NSData response
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
// parse the JSON response into an object
// Here we're using NSArray since we're parsing an array of JSON status objects
_results = [data JSONValue];
NSLog(@"_results:%@",_results);
}
else if ([urlData length] == 0 && error == nil)
{
NSLog(@"Nothing was downloaded.");
}
else if (error != nil){
NSLog(@"Error = %@", error);
}
}];
錯誤代碼:
-JSONValue失敗。錯誤跟蹤是:( 「錯誤域= org.brautaset.JSON.ErrorDomain代碼= 10」JSON後的垃圾\「UserInfo = 0x8195240 {NSLocalizedDescription = JSON後的垃圾}」
不刪除在NSString *數據 – San
中顯示JSON響應沒問題,所以錯誤是說JSON響應已損壞,你能打印出字節的字節,所以我們可以看看它嗎? –