2017-03-27 3 views
-5
{ 
    data =  (
     { 
      href = "XXX" 
      title = "YYY"; 
     }, 
     { 
      href = "XXX"; 
      title = "YYY"; 
     }, 
     { 
      href = "XXX"; 
      title = "YY"; 
     } 
    ); 
} 


Alamofire.request("http://apps.lowerauf.com.pk/news-app/geo2.php").responseJSON { response in 
      if let JSON = response.result.value{ 
       JSON["data"]["href"] 
      } 
     } 

Ich benutze diesen Code, aber es funktioniert nicht und zeigt nichts.JSON funktioniert nicht mit Alamofire 4

Antwort

1

Ihr data enthält Array nicht die Dictionary, so dass Sie eine Schleife durch die data Array müssen und dann jede von ihm verschachtelt JSON zugreifen.

Alamofire.request("http://apps.lowerauf.com.pk/news-app/geo2.php").responseJSON { response in 
    //Considering you are using SwiftyJSON 
    if let json = JSON(response.result.value) { 
     for data in json["data"].arrayValue { 
      print(data["href"]) 
     } 
    } 
} 
+0

@Downvoter Können Sie bitte den Grund unten Abstimmung Antwort hinzufügen kümmern, also werde ich meine Antwort verbessern. –

0

Antwort JSON ist Dictionary und Daten ist ein array of dictionary ..

if let json = response.result.value as? [String:Any]{ 
     if let data = json["data"] as? [[String:String]] { 
      for value in data { 
       print(value["href"]) 
      } 
     } 
    } 
0

Ihre Daten Array

if let json = response.result.value as? [String:Any]{ 
    if let data = json["data"] as? [[String:String]] { 
     for value in data { 
      print(value["href"])} 
    } }