0

我有一个 with Json Delete 方法。我在互联网上冲浪,一无所获。

这是我为 Json Delete 方法尝试过的代码。它只是返回“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 Code=10 \"JSON 后的垃圾\" UserInfo=0x8195240 {NSLocalizedDescription=JSON 后的垃圾}"

4

1 回答 1

2

请求正文通常也不应包含任何数据。DELETE就像GET,只是一个发送到服务器的命令。不应有Content-Type随它发送的标头。尝试删除它。另外,尝试打印出 的内容NSString *data以查看您拥有的内容。

于 2012-12-14T18:58:16.860 回答