Comment puis-je analyser ce JSON?swift analyser JSON à partir de l'URL
{
"telefon":"05538690671"
}
mon code:
let url = NSURL(string: "http://localhost.192.168.1.40.xip.io:8888/store1.php")
//fetching the data from the url
URLSession.shared.dataTask(with: (url as URL?)!, completionHandler: {(data, response, error) -> Void in
if let jsonObj = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? NSDictionary {
//printing the json in console
print(jsonObj!.value(forKey: "telefon")!)
désolé pour mon anglais
désolé, quand je suis tracer ce saut de code de dataTask à la fin du code –
@ ÜmitGündüz Cela signifie une des conditions de 'guard' ont échoué. –
@ ÜmitGündüz J'ai ajouté une nouvelle version avec plus de débogage dans certaines des conditions d'échec. –