Neu bei der JSON-API, wie greife ich auf die Werte in Objective-C zu?IOS

Programmierung für iOS
Guest
 Neu bei der JSON-API, wie greife ich auf die Werte in Objective-C zu?

Post by Guest »

Unten ist mein Code für den Zugriff auf die JSON-API von Edmunds.com. Dies funktioniert perfekt, um auf die Informationen zuzugreifen. Ich habe nur Probleme beim Zugriff auf die Schlüssel-Wert-Paare.

Code: Select all

NSURL *equipmentURL = [NSURL URLWithString: [NSString stringWithFormat:@"https://api.edmunds.com/api/vehicle/v2/styles/%@/equipment?fmt=json&api_key=%@", self.carID, apiKey]];

NSData *jsonData = [NSData dataWithContentsOfURL:equipmentURL];

NSError *error = nil;

NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];

self.engineArray = [NSMutableArray array];

NSArray *equipmentArray = [dataDictionary objectForKey:@"equipment"];

for (NSDictionary *carInfoDictionary in equipmentArray) {

NSArray *attributes = [carInfoDictionary objectForKey:@"attributes"];
NSLog(@"%@", attributes);

}
Im NSLog aus dem obigen Code wird Folgendes angezeigt:

Code: Select all

2016-11-03 10:21:26.029 CarWise[25766:1896339] (
{
name = "Engine Immobilizer";
value = "engine immobilizer";
},
{
name = "Power Door Locks";
value = "hands-free entry";
},
{
name = "Anti Theft Alarm System";
value = "remote anti-theft alarm system";
}
)
Meine Hauptfrage ist, wie ich auf den Namen und den Wert für jedes Array zugreifen kann? Nehmen wir an, ich möchte ein UILabel erstellen, das die Zeichenfolge eines der Werte enthält?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post