【问题标题】:siwfty json parsing failssiwfty json 解析失败
【发布时间】:2016-05-31 18:39:22
【问题描述】:

我正在制作一个 ios 应用程序...我正在使用 alamofire 和 swiftyjson 进行 api 调用。但 swiftyjson 无法解析以下 json 响应...

{"meta":{"status":200},"response":"You will be notified when we will be in your region"}

我的代码:

Alamofire.request(.POST, newsletterRegistraionUrl, parameters: params)
            .responseString { response in

                indicator.stopAnimating();
                switch(response.result){
                case .Success:
                    if let r = response.result.value {
                        var jsonResponse = JSON(r);

                        print(jsonResponse.stringValue)
                        if jsonResponse[META][STATUS].isExists() {
                            if jsonResponse[META][STATUS].intValue == apiSuccess {
                                if let message = jsonResponse[RESPONSE].string {
                                    self.makeAlert(message);
                                    self.performSegueWithIdentifier(NEWSLETTERSUCCESSIDENTIFIRE, sender: self);
                                }
                            }else {
                                self.makeAlert(APIERROR);
                            }
                            print(jsonResponse[META][STATUS].intValue)
                            print("sss")
                        }
//                        

                    }
                    break;
                case .Failure(let error):
                    print(error.description);
                    self.makeAlert(APIERROR);
                    break;
                }



        }

解析后我得到的状态值为0。不确定我在哪里搞砸了......

【问题讨论】:

    标签: ios swift alamofire swifty-json


    【解决方案1】:

    你能检查一下 NSAppTransportSecurity 信息.Plist

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
    

    添加并尝试一下

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-05
      • 2015-10-19
      • 2015-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-05
      相关资源
      最近更新 更多