2016-02-14 69 views
1

GET方法Alamofire我有一些问题。当我的数据我有错误:Alamofire扁平错误:意外地发现零,而解包一个可选值

EXC_BAD_INSTRUCTION(代码= EXC_I386_INVOP,子码=为0x0) 致命错误:意外发现零而展开的可选值

我在做什么错?我的代码:

 let URLString = "http://MyURLWebService..."; 
     Alamofire.request(.GET, URLString) 
     .responseJSON { (response) in 
      print(response.request) // original URL request 
      print(response.response) // URL response 
      print(response.data)  // server data 
      print(response.result) // result of response serialization 

      if let JSON = response.result.value { 
       print(JSON["Phones"] as! String) 
       //print("JSON: \(JSON)") 
      } 

    } 
+0

我的格式REST API数据: [{电话 “:” + 1(100)111-22-33“,”Phones2“:null}] – Dim

回答

0

这是工作:

  if let jsonResult = response.result.value { 
       let Address = jsonResult[0]["Address"] 
       let Phones = jsonResult[0]["Phones"] 
       print("JSON: Address: \(Address)") 
       print("JSON: Phones: \(Phones)") 
      } 

我希望它能帮助别人

0

我觉得JSON对象与"Phones"作为名称的成员。所以最好使用改为print(JSON["Phones"] as? String)

编辑:

你的JSON字符串已损坏。您必须用双引号包装Phones

这样的:

[{"Phones":"+1 (100) 111-22-33","Phones2":null}]

相关问题