ios - alamofire-将 json 字符串作为参数传递

标签 ios objective-c swift afnetworking alamofire

我想传递json字符串作为参数,但它只允许字典:

Alamofire.request(.POST,"myURL", parameters: "HERE I WANT STRING", encoding: .JSON).responseJSON
 { response in
    if let JSON = response.result.value {
                    print("JSON: \(JSON)")
                }
            } 

我认为我的服务器接受 json 格式的参数。

最佳答案

别担心。 只需将 Json 制作成这个并用作参数即可

let jsonObject: [String: AnyObject] = [
            "status": "0" , "secondparameter" : "something"]


Alamofire.request(.POST,"myURL", parameters : jsonObject , encoding: .JSON).responseJSON
 { response in
    if let JSON = response.result.value {
                    print("JSON: \(JSON)")
                }
            } 

希望对你有帮助。

关于ios - alamofire-将 json 字符串作为参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36614597/

相关文章:

ios - “AppDelegate”仅适用于 iOS 10.0 或更新版本

ios - Obj-c 协议(protocol)属性未在符合类中实现

ios - 获取视频轨道的大小

swift - Xcode 中 tic tac toe 的手势识别器问题

ios - 当不在相机视野中时停止 SKVideoNode 播放

ios - Objective-C : For loop is finished before image is finished

objective-c - 从主线程( cocoa )终止辅助线程

swift - RxSwift 链接 : What is a better way of writing this in Rxswift?

ios - metaio 的 mach-o 链接器错误

ios - 如何选择以编程方式创建的文本字段?