2016-07-14 5 views
-1

こんにちは私はSTRAVA APIに接続しており、その応答からJSON形式で応答を得ています。以下のJSONデータから、ユーザー名、都市、国などを取得する必要がありますPHPのStrava APIからJSONデータをデコードする

これはどのようにPHPやJavascriptを使って実現できますか?以下は、私がAPIから得たサンプルレスポンスです。

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

あなたが欲しいものを別の配列を作成し、 'PHPでjson_decode'を使用しますので、APIの使用からusernamecitycountryを取得する

は、これらをエコーすることにより、この

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

チェックのように試すことができます限られた要素で。 – C2486

+0

@Rishiあなたはそれを取得する方法のサンプルを私に提供してもらえますか? – ShivLeela

+0

あなたが表示する応答はjson形式ではありません。あなたは '$ var [0] - > athlete-> username'を使うことができます。 –

答えて

1

サンプルレスポンスは配列とオブジェクトの組み合わせではありませんが、

echo "Username : $username<br>"; 
echo "City : $city <br>"; 
echo "Country : $country <br>"; 
関連する問題