json_decode一种数组

时间:2016-03-12 06:41:30

标签: php arrays json curl

大家好我面临着从卷曲响应中解码数组并将结果值赋值给变量的问题。我想将下面数组中auth_token的值赋给php中的变量。< / p>

{ "status": true, "result": { "daily_prize_num": 0, "daily_prize_amount": 0, "monthly_prize_num": 0, "monthly_prize_total": 0, "daily_chances": 0, "monthly_chances": 0, "chances_left": 0, "user": { "phone": "91889888888", "country_id": "2", "created_at": 1457242503, "verified": 0, "device_id": "x55769w0ecb4f9k3", "device_token": "APA91bF4ETz2QhQZ8JcbB6TQHPdYa6v7TBnEIrjRySftQrjCVuvYs7owqqTgS76cHN6xmGzzA_rkRuOYuXIo5Po0ngOqo0h_NyAORa899WAwmSgiALdXsjo", "referral_code": "", "referral_code_used": "4hTRSK", "auth_token": "8fd3bd001a3bf5a47021924a80ccb0068cf6f7ccaf19b591b8232e0bfd63aa26b4d19ee589d7ab2dd8f07317936aa76b9762446ae6372ea800a6151460baa81a", "is_active": 1, "id": 88494, "is_first_time": true, "profile_completed": false } } }

2 个答案:

答案 0 :(得分:1)

使用json_decode并访问数组:

$r = json_decode ($data, true);
$auth = $r ['result']['user']['auth_token'];

答案 1 :(得分:0)

$var = json_decode('{"status":true,"result":{"daily_prize_num":0,"daily_prize_amount":0,"monthly_prize_num":0,"monthly_prize_total":0,"daily_chances":0,"monthly_chances":0,"chances_left":0,"user":{"phone":"91889888888","country_id":"2","created_at":1457242503,"verified":0,"device_id":"x55769w0ecb4f9k3","device_token":"APA91bF4ETz2QhQZ8JcbB6TQHPdYa6v7TBnEIrjRySftQrjCVuvYs7owqqTgS76cHN6xmGzzA_rkRuOYuXIo5Po0ngOqo0h_NyAORa899WAwmSgiALdXsjo","referral_code":"","referral_code_used":"4hTRSK","auth_token":"8fd3bd001a3bf5a47021924a80ccb0068cf6f7ccaf19b591b8232e0bfd63aa26b4d19ee589d7ab2dd8f07317936aa76b9762446ae6372ea800a6151460baa81a","is_active":1,"id":88494,"is_first_time":true,"profile_completed":false}}}') ;

$token = $var['result'] ['user'] ['auth_token'] ;