Friday, February 3, 2023
HomeiOS Developmentios - Can't parse mannequin json

ios – Can’t parse mannequin json

I attempt to parse JSON –

I created subsequent mannequin:

struct Mannequin: Decodable {
    var title: Title
    var content material, excerpt: Content material
    var yoastHeadJSON: YoastHeadJSON

struct Content material: Decodable {
    var rendered: String

struct Title: Decodable {
    var rendered: String

struct YoastHeadJSON: Decodable {
    var ogImage: [OgImage]

struct OgImage: Decodable {
    var url: String

And use subsequent code to parse this mannequin:

static func getInfo(searh: String, web page: Int, completion: @escaping ([Model]) -> ()) {
        let urlToGet = " page=(web page)"

        guard let urlString = URL(string: urlToGet) else {return}
        let fetch = URLSession.shared.dataTask(with: urlString) { (knowledge, responce, error) in
            guard let information = knowledge else {return}

            guard let present = attempt? JSONDecoder().decode([Model].self, from: information) else {return}

But it surely would not works. If I take away

var yoastHeadJSON: YoastHeadJSON

from mannequin it really works. However with it it would not work. The place is my error?



Please enter your comment!
Please enter your name here

one × three =

Most Popular

Recent Comments