jsonserialization with nested object

["statusFlag": 1, "confirmResult": { customerDetail = { directTopup = 0; paymentMethod = "ideal"; skipSMS = 0; trusted = 0; }; invoiceID = sdLrhz1652515770; message = "Unable to process the payment."; products = { product = ( ); total = 0; }; status = 0; }]


          guard let jsonresponse = try JSONSerialization.jsonObject(with: jsondata,  options: []) as? [String: Any] else { return }

let confirmresult = jsonresponse["confirmResult"]

im able to get the confirmResult. But i need to get one more level deeper and get the value of status . Can someone help how to parse further ?

["statusFlag": 1, 
 "confirmResult": {
        customerDetail = { directTopup = 0; paymentMethod = "ideal"; skipSMS = 0; trusted = 0; }; 
        invoiceID = sdLrhz1652515770; 
        message = "Unable to process the payment."; 
        products = { product = ( ); total = 0; };
       status = 0; 
     }
]

guard let jsonresponse = try JSONSerialization.jsonObject(with: jsondata,  options: []) as? [String: Any] else { return }
let confirmresult = jsonresponse["confirmResult"]

What do you get exactly in confirmresult?

What is customerDetail ? Is it a String ?

I don't understand the data structure.

What does this mean :

customerDetail = { directTopup = 0; paymentMethod = "ideal"; skipSMS = 0; trusted = 0; };

Have you defined a Result class or struct ?

If so, use JSONSerialization.jsonObject again on jsonresponse as Data

Plese show complete code.

Now that you have your JSONSerialization-based code working, you should consider whether this could be implemented more easily / safely / etc. using the Decodable protocol and the JSONDecoder class, if you have’t looked into this approach already.

jsonserialization with nested object
 
 
Q