2016-06-15 24 views
-2

Flipkart Affiliate APIを使用して迅速かつ初めての新機能です。私はすべてのプロダクトを取得するコードを書いています。ヘッダーは要求に応じて使用されます。 ベローは私が試みているコードです。しかし、何も譲らない。助けてください !! 私は正しい要求を送信するかどうか、また回答を得る方法を教えてください。Flipkart APIの使用JSONレスポンスを取得できません

 super.viewDidLoad() 

     let urlString ="https://affi/affiliate/1.0/feeds/.." 

     let request = NSMutableURLRequest(URL: NSURL(string: urlString)!) 
     request.addValue("xxx", forHTTPHeaderField: "Fk-Affiliate-Id") 
     request.addValue("xxxxx", forHTTPHeaderField: "Fk-Affiliate-Token") 
     request.addValue("application/json", forHTTPHeaderField: "Content-Type") 
     request.addValue("application/json", forHTTPHeaderField: "Accept") 
     let body: Dictionary <String,String>= Dictionary() 
     let session = NSURLSession.sharedSession() 
     request.HTTPMethod = "POST" 

     do { 
      request.HTTPBody = try NSJSONSerialization.dataWithJSONObject(body ,options: []) 
     } catch { 
      print(error) 
      return 
     } 
     let task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in 
      // handle error 
      guard error == nil else { return } 
      print("Response: \(response)") 
      let strData = NSString(data: data!, encoding: NSUTF8StringEncoding) 
      print("Body: \(strData)") 

      let json: NSDictionary? 
      do { 
       json = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableLeaves) as? NSDictionary 
      } catch let dataError { 
       // Did the JSONObjectWithData constructor return an error? If so, log the error to the console 

       print(dataError) 
       let jsonStr = NSString(data: data!, encoding: NSUTF8StringEncoding) 
       print("Error could not parse JSON: '\(jsonStr)'") 
       // return or throw? 
       return 
      } 

     }) 

     task.resume() 
} 

答えて

-1

試してみてください。

do { 
json = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableLeaves) as? NSDictionary 
print(json) //Prints the received JSON if the request made is correct. 
} 
+0

まあ、彼はそれをやったと、受信したJSONをしてください印刷する適切な方法は何でしょう理由を説明downvoted人だろうか? – Dershowitz123

関連する問題