2016-07-14 11 views
-1
dekodieren

Hallo Ich habe mit STRAVA API verbunden und ich bekomme die Antwort im JSON-Format, von dieser Antwort muss ich nur einige Benutzerprofildetails erhalten. Aus den folgenden JSON-Daten muss ich Benutzernamen, Stadt, Land etc. abrufen.JSON-Daten von Strava API in PHP

Wie kann ich dies mit PHP oder Javascript erreichen? Im Folgenden finden Sie die Probe Antwort, die ich von der API ist nicht

Array ([0] => stdClass Object ([athlete] => stdClass Object ([id] => 8022511 [username] => adamjones [resource_state] => 2 [firstname] => Adam [lastname] => Jones [city] => Hyderabad [state] => Telangana [country] => India [sex] => M [premium] => [created_at] => 2015-02-23T06:37:17Z [updated_at] => 2016-03-15T04:33:06Z [badge_type_id] => 0 [profile_medium] => https://graph.facebook.com/v2.1/10004102544/picture?height=256&width=256 [profile] => https://graph.facebook.com/v2.1/10004102544/picture?height=256&width=256 [friend] => [follower] =>) [description] => [distance] => 42031.71247288 [elevation_gain] => 241.8005935689 [id] => 3878028 [map] => stdClass Object ([id] => r3878028 [summary_polyline] => gqoiByqh}[email protected][email protected]@[email protected]@zNjSxBxGwH|B|I|DfAhoBtTrlA|[email protected]{[email protected]{[email protected]}W`BofBrRkwAj[vLjCtRpJvLdHrObR|KxA|[email protected]|[email protected][email protected]@[email protected]@[email protected]`QwByAgsBzcA}EpAiEgEeC^cBhA`@|[email protected]@~][email protected]@mGxB{[email protected]|@[email protected]{BzAskAeDioBuT}DgA{AeHkC|[email protected]@[email protected]@[email protected] [resource_state] => 2) [name] => My Fav [private] => [resource_state] => 2 [starred] => [sub_type] => 1 [timestamp] => 1451823069 [type] => 1)) 
+0

Verwendung 'json_decode' in php, erstellen Sie ein anderes Array, was Sie wollen:

So wie diese versuchen kann durch Echo diese

//let say your variable name is '$apiResponse' $username = $apiResponse[0]->athlete->username; $city = $apiResponse[0]->athlete->city; $country = $apiResponse[0]->athlete->country; 

Scheck username, city, country von API Verwendung zu erhalten mit begrenzten Elementen. – C2486

+0

@Rishi können Sie mir bitte ein Beispiel zur Verfügung stellen, wie man es zurückholt? – ShivLeela

+0

Die Antwort, die Sie anzeigen, ist nicht im JSON-Format. Sie können '$ var [0] -> athlet-> Benutzername' verwenden –

Antwort

1

Obwohl Ihre Probe Antwort bekam die Kombination von Array und Objekt JSon.

echo "Username : $username<br>"; 
echo "City : $city <br>"; 
echo "Country : $country <br>";