0
Ich versuche, eine URL-Anfrage (in Wörterbuch "Fahrzeuge") in einem JSON zu lesen, aber das Array wird leer Das ist der JSON und ich muss das Wörterbuch und die URL lesen sind in FahrzeugenLesen Sie eine URL HTTPS in einer JSON-Datei swift
{
"count": 87,
"next": "https://swapi.co/api/people/?page=2",
"previous": null,
"results": [
{
"name": "Luke Skywalker",
"height": "172",
"mass": "77",
"hair_color": "blond",
"skin_color": "fair",
"eye_color": "blue",
"birth_year": "19BBY",
"gender": "male",
"homeworld": "https://swapi.co/api/planets/1/",
"films": [
"https://swapi.co/api/films/2/",
"https://swapi.co/api/films/6/",
"https://swapi.co/api/films/3/",
"https://swapi.co/api/films/1/",
"https://swapi.co/api/films/7/"
],
"species": [
"https://swapi.co/api/species/1/"
],
"vehicles": [
"https://swapi.co/api/vehicles/14/",
"https://swapi.co/api/vehicles/30/"
],
Dies ist der Code, dass ich
versuchenif let results = json["results"] as? [[String : AnyObject]] {
var finalArray2 : [String] = []
for result in results {
if let dict = result as? [String: Any], let vehicles = dict["vehicles"] as? String{
self.URLveicoli = vehicles
//print(self.nomepersonaggio)
print(self.URLveicoli)
//finalArray.append(name)
finalArray2.append(vehicles)
}
}
print(finalArray2)
}
Kann nicht konvertieren Wert vom Typ '[Zeichenfolge]' zu erwarten Argument Typ 'String' – YouFred
Um ein Array an ein Array anzuhängen, verwenden Sie die Methode 'append (contentsOf:)'. – Bilal