title: Slow JSONSerialization Parsing Swift 3.0
body: <p>I'm building an application able to return books info (Title,Description,Author ...) using Google Books Api.</p>
  
  <p>The problem is that after detecting ISBN (International Standard Book Number)from the previous view it takes time to show details on my current view.</p>
  
  <p><a href="https://i.stack.imgur.com/Cq0pe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cq0pe.png" alt="enter image description here"></a></p>
  
  <p>After 1-3 seconds I get parsing result:</p>
  
  <p><a href="https://i.stack.imgur.com/4gQBn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4gQBn.png" alt="enter image description here"></a></p>
  
  <p>I'm using this method to get data using google books api:</p>
  
  <pre><code>func getBookInfo(isbn: String) {
      guard let url = URL(string: "https://www.googleapis.com/books/v1/volumes?q=isbn:\(isbn)") else {
          print("***********************************")
          print("the url is not valid")
          return
      }
      URLSession.shared.dataTask(with: url, completionHandler: {data, response, error -&gt; Void in
          guard error == nil else {
              print(response)
              print(error!.localizedDescription)
              return
          }
          guard let data = data else {
              print("no error but no data")
              print("***********************************")
              print(response)
              return
          }
          guard let jsonResult = try? JSONSerialization.jsonObject(with: data, options: []) else {
              print("the JSON is not valid")
              return
          }
  
  
          if let arrayOfLa = (jsonResult as AnyObject).value(forKeyPath: "items.volumeInfo.language") as? [String] {
  
              DispatchQueue.global(qos: .userInitiated).async {
                  // Bounce back to the main thread to update the UI
                  DispatchQueue.main.async {
                      print("opopopop")
                      print (arrayOfLa)
  
                  }
              }
  
          }
  
  
  
  
          ///finish language
          if let arrayOfTitles = (jsonResult as AnyObject).value(forKeyPath: "items.volumeInfo.title") as? [String] {
  
              DispatchQueue.global(qos: .userInitiated).async {
                  // Bounce back to the main thread to update the UI
                  DispatchQueue.main.async {
                      self.title = "\(arrayOfTitles[0])"
  
                  }
              }
  
          }
          if let arrayOfDesc = (jsonResult as AnyObject).value(forKeyPath: "items.volumeInfo.description") as? [String] {
  
  
  
              DispatchQueue.global(qos: .userInitiated).async {
                  // Bounce back to the main thread to update the UI
                  DispatchQueue.main.async {
                      self.bookDescription.text =  "\(arrayOfDesc[0])"
                  }
              }
  
  
  
          }
  
          //start here 
  
          if let arrayOfPictures = (jsonResult as AnyObject).value(forKeyPath: "items.volumeInfo.imageLinks.thumbnail") as? [String] {
  
              print ("\(arrayOfPictures[0])")
              self.bookPicture = "\(arrayOfPictures[0])"
              if let checkedUrl = URL(string: "\(arrayOfPictures[0])") {
                  self.imageBook.contentMode = .scaleAspectFit
                  self.downloadImage(url: checkedUrl)
              }
                             }
  
  
  
  
          //end here
  
          //start author here
  
          if let arrayOfAuthors = (jsonResult as AnyObject).value(forKeyPath: "items.volumeInfo.authors") as? [[String]]  {
              DispatchQueue.global(qos: .userInitiated).async {
                  // Bounce back to the main thread to update the UI
                  DispatchQueue.main.async {
                      self.authorText.text =  "\((arrayOfAuthors[0])[0])"
                  }
              }
  
          }
  
          // finish author here
          //start categories here
  
          if let arrayOfCategories = (jsonResult as AnyObject).value(forKeyPath: "items.volumeInfo.categories") as? [[String]]  {
              DispatchQueue.global(qos: .userInitiated).async {
                  // Bounce back to the main thread to update the UI
                  DispatchQueue.main.async {
  
  
                      self.categorieText.text =  "\((arrayOfCategories[0])[0])"                 }
              }
  
          }
  
          // finish caetegories here
  
  
  
  
      }).resume()
  }
  </code></pre>
  
  <p>and I'm calling it on the ViewWillAppaer</p>
  
  <pre><code>override func viewWillAppear(_ animated: Bool) {
  
      super.viewWillAppear(animated)
      getBookInfo(isbn: isbnCode)
  }
  </code></pre>
  
  <p>Any suggestions ?</p>