2017-02-09 78 views
0

变量我使用的是充电API。 API以Json格式接收响应。我需要从PHP中的Json响应中的变量中存储输出值。获取引起从JSON输出

// Response received from API url 
$output = '{"data":[{"user":"abcd123","bal":"500","error_code":200,"resText":"Success"}]}'; 

//Decoding output 
$json = json_decode($output, true); 

//Print 
print_r($json); 

//Store a value as variable 
$bal = $json['bal']; 

获取错误BAL是不确定的指数。

请帮我用正确的方式来获得从API响应变量$ BALBAL值。

+1

'print_r($ json);'并遵循结构。 – AbraCadaver

回答

2

你的JSON对象实际存储的所有数据在称为data一个属性,其又对象数组(只是1真的)。因此,请尝试

$json['data'][0]['bal'] 
+0

非常感谢!有效。 –