2016-06-15 9 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

관련 문제