如何使用SwiftyJson解析json响应。下面是我的代码和响应

问题描述:

func authenticateUser() 
{  

    Alamofire.request("http://dev.myvmanager.com/vManagerMobileWebService/api/vMobile/Authenticate_iNotifications?username=ssrikanth&password=bA2135&device=iPhone&device_token=iPhone&[email protected])[email protected]").responseJSON 
     { 
      response in 
      debugPrint(response)  
    } 
} 

只要使用此构造从SwiftyJSON和输入的响应数据

Alamofire 
     .request("http://dev.myvmanager.com/vManagerMobileWebService/api/vMobile/Authenticate_iNotifications?username=ssrikanth&password=bA2135&device=iPhone&device_token=iPhone&[email protected])[email protected]") 
     .responseJSON { response in 
      debugPrint(response) 
      if let actualData = response.data { 
       let json = JSON(data: actualData) 
       debugPrint(json) 
      } 
    } 

从JSON

let json = JSON(data: actualData) 
if let userName = json[0]["login_name"].string { 
    //Now you got your value 
} 

检索数据的详细信息,请看看https://github.com/SwiftyJSON/SwiftyJSON和示例项目。

这里也是JSON映射器的一个很好的比较

https://github.com/bwhiteley/JSONShootout

+0

当我实现以上行,我得到这样 一个错误“无法转换数据类型响应预期参数类型数据的价值” –

+0

@SachitPhilip测试后,我得到了这个错误_Cannot类型'DataResponse转换价值的数据类型'为预期的参数类型'Data'_ - >我更新了我的答案,它应该有望现在的工作现在 – KaraBenNemsi

+0

@ KaraBenMemsi 我现在得到了这样的回复 [ { “描述”:空, “消息”:空, “vmanager_account”: “真”, “USER_ID”: “174”, “LOGIN_NAME”: “ssrikanth”, “USER_NAME”:“苏里亚SRIKANTH “ ”owner_id“: ”1“, ”USER_EMAIL“: ”[email protected]“, ”CUSTOMER_ID“: ”20“, ”vmanager_cc“: ”真“, ”vmanager_tp“:” 真”, “CUSTOMER_NAME”: “VCOM解决方案”, “is_so”: “0” } ] 假设如果我想检索this..for例如值 “LOGIN_NAME” 该怎么做? –