Q:

How to get json fields? 

I follow a lesson from one course
And I need to get json, but i want get another json than in a lesson. 
So this is my json:
https://api.scryfall.com/cards/search?q=half
And code:
struct Card {
    var cardId: String
var name: String
var imageUrl: String
var text: String

init?(dict: [String: AnyObject]){
    guard let name = dict["name"] as?  String,
        let cardId = dict["cardId"] as?  String,
        let imageUrl = dict["imageUrl"] as?  String,
        let text = dict["text"] as?  String else { return nil }

self.cardId = cardId
self.name = name
self.imageUrl = imageUrl
self.text = text
}
}

class CardNetworkService{
     private init() {}

static func getCards(url: String, completion: @escaping(GetCardResponse) -> ()) {
    guard let url = URL(string: url) else { return }

    NetworkService.shared.getData(url: url) { (json) in
        do {
            print ("ok1")
            let response = try GetCardResponse(json: json)
            print ("ok2")
            completion(response)
        } catch {
            print(error)
        }
    }
}
}

class NetworkService {

private init() {}

static let shared = NetworkService()

func getData(url: URL, completion: @escaping (Any) -> ()) {
    let session = URLSession.shared

    session.dataTask(with: url) { (data, response, error) in
        guard let data = data else { return }

        do {
            let json = try JSONSerialization.jsonObject(with: data, options: []) 
            DispatchQueue.main.async {
                completion(json)
            }
            print(json)
        } catch {
            print(error)
        }
        }.resume()
}
}

  struct GetCardResponse{
    let cards: [Card]

init(json: Any) throws {
    guard let array = json as? [[ String: AnyObject]] else { throw NetworkError.failInternetError }

    var cards = [Card]()
    for dictionary in array {
        guard let card = Card(dict: dictionary) else { continue }
        cards.append(card)
    }
    self.cards = cards
}
   }

Problem in struct GetCardResponse and [[String: AnyObject]] because I dont know how to parse this type of json.  I tried to change them in the likeness of json.  But I dont really understand how it works and in which part of code i need to put json["data"] or something like this... Help pls.  I just want get json fields tcgplayer_id, name, art_crop

A:

You are wrong get entry of data field. 
First you need get data field in json.  And parse to deeper. 
Try use the code. 
struct GetCardResponse{
  let cards: [Card]

  init(json: Any) throws {
    guard let jsonObject = json as? [ String: Any], let data = jsonObject["data"] as? [[ String:AnyObject]] else { throw NetworkError.failInternetError }

    var cards = [Card]()
    for dictionary in data {
      guard let card = Card(dict: dictionary) else { continue }
      cards.append(card)
    }
    self.cards = cards
  }
}

UPDATE:
init function in Card has something wrong.  In your json cardId is not found
Card class maybe like this because cardId, imageUrl, text maybe not found.  It is optional 
struct Card {
  var cardId: String? 
  var name: String
  var imageUrl: String? 
  var text: String? 

  init?(dict: [String: AnyObject]){
    guard let name = dict["name"] as?  String else { return nil }

    self.cardId = dict["cardId"] as?  String
    self.name = name
    self.imageUrl = dict["imageUrl"] as?  String
    self.text = dict["text"] as?  String
  }
}

