Rest API - JSON Ergebniss verarbeiten

Hallo zusammen, Ich stehe Aktuell vor einem kleinen Problem bezüglich der JSON ausgabe der Rest API. Ich habe mich bislang an die im Wiki beschriebene Anleitung gehalten. Dort bekomm ich Beispielsweise durch $client-\>call('version', ApiClient::METHODE\_GET); die Antwort im Browser: HTTP: 200 Success Array ( [version] =\> 4.2.3 [revision] =\> 201404291539 ) Die Ausgabe entspricht ja nun bereits einen JSON Array. Wie kann ich dieses Array abfangen und verarbeiten? Bin für jede Hilfe Dankbar. Gruss Norman

OK… Bin alleine auf die Lösung gekommen. Möchte diese hier gerne zur verfügung stellen falls noch jemand vor dem gleichen Problem steht. include "client\_ini.php"; class ApiClient { const METHODE\_GET = 'GET'; const METHODE\_PUT = 'PUT'; const METHODE\_POST = 'POST'; const METHODE\_DELETE = 'DELETE'; protected $validMethods = array( self::METHODE\_GET, self::METHODE\_PUT, self::METHODE\_POST, self::METHODE\_DELETE ); protected $apiUrl; protected $cURL; public function \_\_construct($apiUrl, $username, $apiKey) { $this-\>apiUrl = rtrim($apiUrl, '/') . '/'; //Initializes the cURL instance $this-\>cURL = curl\_init(); curl\_setopt($this-\>cURL, CURLOPT\_RETURNTRANSFER, true); curl\_setopt($this-\>cURL, CURLOPT\_FOLLOWLOCATION, false); curl\_setopt($this-\>cURL, CURLOPT\_HTTPAUTH, CURLAUTH\_DIGEST); curl\_setopt($this-\>cURL, CURLOPT\_USERPWD, $username . ':' . $apiKey); curl\_setopt($this-\>cURL, CURLOPT\_HTTPHEADER, array( 'Content-Type: application/json; charset=utf-8', )); } public function call($url, $method = self::METHODE\_GET, $data = array(), $params = array()) { if (!in\_array($method, $this-\>validMethods)) { throw new Exception('Invalid HTTP-Methode: ' . $method); } $queryString = ''; if (!empty($params)) { $queryString = http\_build\_query($params); } $url = rtrim($url, '?') . '?'; $url = $this-\>apiUrl . $url . $params; $dataString = json\_encode($data); curl\_setopt($this-\>cURL, CURLOPT\_URL, $url); curl\_setopt($this-\>cURL, CURLOPT\_CUSTOMREQUEST, $method); curl\_setopt($this-\>cURL, CURLOPT\_POSTFIELDS, $dataString); $result = curl\_exec($this-\>cURL); $httpCode = curl\_getinfo($this-\>cURL, CURLINFO\_HTTP\_CODE); return $this-\>prepareResponse($result, $httpCode); } public function get($url, $params = array()) { return $this-\>call($url, self::METHODE\_GET, array(), $params); } public function post($url, $data = array(), $params = array()) { return $this-\>call($url, self::METHODE\_POST, $data, $params); } public function put($url, $data = array(), $params = array()) { return $this-\>call($url, self::METHODE\_PUT, $data, $params); } public function delete($url, $params = array()) { return $this-\>call($url, self::METHODE\_DELETE, array(), $params); } protected function prepareResponse($result){ return $result; } } $ergebnis = $client-\>get('articles'); header('Content-type: application/json; charset=utf-8'); $array = json\_decode($ergebnis,true); print\_r ($array); ?\> Will man nun Beispielsweise den Ersten Artikel Namentlich darstellen dann: echo $array["data"]["0"]['name']; In diesem Sinne Gruss Norman

2 „Gefällt mir“