Swift 2 Json Alamofire错误" ..期望1个参数,但指定了3个" iOS 9 Xcode 7

时间:2015-12-05 11:17:05

标签: json xcode ios9 alamofire

我已尝试在我的应用中实施JSON解析,以便从我的网站上查看最新的Wordpress帖子。

现在我有以下错误:

"闭包参数列表的上下文类型需要1个参数,但指定了3个"

"问题代码"

func getPosts(getposts : String)
{
    Alamofire.request(.GET, getposts, parameters:parameters)
        .responseJSON { request, response, result in

            switch result
            {
                case .Success(let data):

                    self.json = JSON(data)
                    self.tableView.reloadData()

                case .Failure(let error):
                    print("Request failed with error: \(error)")
            }
    }
}

希望你能帮助我(:

祝你好运!

2 个答案:

答案 0 :(得分:3)

我知道了!

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        DataContext = new MainWindowViewModel();
    }
}

public class MainWindowViewModel
{
    public MainWindowViewModel()
    {
        Menu1Executed = new DelegateCommand(ShowMenu1);
    }

    public ICommand Menu1Executed { get; set; }

    private void ShowMenu1(object obj)
    {
        // Yay!
    }
}

public class DelegateCommand : ICommand
{
    private readonly Action<object> execute;
    private readonly Predicate<object> canExecute;

    public DelegateCommand(Action<object> execute)
        : this(execute, null)
    { }

    public DelegateCommand(Action<object> execute, Predicate<object> canExecute)
    {
        if (execute == null)
            throw new ArgumentNullException("execute");

        this.execute = execute;
        this.canExecute = canExecute;
    }

    #region ICommand Members

    [DebuggerStepThrough]
    public bool CanExecute(object parameter)
    {
        return canExecute == null ? true : canExecute(parameter);
    }

    public event EventHandler CanExecuteChanged
    {
        add { CommandManager.RequerySuggested += value; }
        remove { CommandManager.RequerySuggested -= value; }
    }

    public void Execute(object parameter)
    {
        execute(parameter);
    }

    #endregion
}

答案 1 :(得分:0)

将基本URL和参数用于服务和方法类型的简单代码。

 Alamofire.request(.POST, "http://www.abc.cpm", parameters: ["consumer_key": "fnfkdkdndf"]).responseJSON { response in

           print(response)

        }