如何使用SwiftHTTP swift3

时间:2017-03-21 11:31:16

标签: ios swift3

我正在尝试使用swiftHTTP在swift中发布一个帖子请求

我的JSON正文如下所示

 {
  "EmailId":"abc@gmail.com",
  "UserSecurityQuestions": [
  {
  "Id": 1,
  "SecurityQuestions": "What is your favourate pet name",
  "Answer":"candy"
  },
  {
  "Id": 2,
  "SecurityQuestions": "What was your favorite place to visit as a   child?",
  "Answer":"paris"
  },

  {
  "Id": 8,
  "SecurityQuestions": "What is your favorite movie?",
  "Answer":"parisin"
  }
  ]
 }

我试图通过以下方式调用它

    let datasecqArray = [ ["Id" : self.secques1,"SecurityQuestions" :    SecurityQuestionOneTextField.text!, "Answer" :AnswerOneTextField.text!],["Id" : self.secques2,"SecurityQuestions" : SecurityQuestionTwoTextField.text!, "Answer" :AnswerTwoTextField.text!],["Id" : self.secques3,"SecurityQuestions" : SecurityQuestionThreeTextField.text!, "Answer" : AnswerThreeTextField.text!] ]

    let useremail = PHCConstant.defaults.value(forKey: "emailForUser") as! String
    let data = try? JSONSerialization.data(withJSONObject: datasecqArray, options: [])
    let string = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
    let parDic = ["EmailId":useremail,"UserSecurityQuestions": string! as Any] as [String:Any]

我将parDic常量作为帖子中的param发布。在打印parDic时,我得到的输出为

  [
   "EmailId":"abc@gmail.com",
   "UserSecurityQuestions": [
   {
   "Id": 1,
   "SecurityQuestions": "What is your favourate pet name",
    "Answer":"candy"
   },
  {
  "Id": 2,
  "SecurityQuestions": "What was your favorite place to visit as a      child?",
  "Answer":"paris"
  },

 {
 "Id": 8,
 "SecurityQuestions": "What is your favorite movie?",
 "Answer":"parisin"
 }
]
]

如何获取JSON主体中显示的输出,而不是上面的数组中的数组..请帮助我并为我的语法道歉

0 个答案:

没有答案