我从Web服务API获得了以下响应代码。
$data = sql_query,
$columns = array(
array('type_checkbox' => 'name_of_id_to_look_for')
array('type_select' =>array(
'select_class' => 'headline_name',
'select_value1' => 'select_name1',
'select_value2' => 'select_name2'))
array('type_text' => 'headline_name')
);
如何使用php从此响应中提取各个变量,如balance,batch_id,cost,num_messages等?
答案 0 :(得分:0)
您是否已收到JSON的API响应,并使用过json_decode($response)
?它返回对象。您可以将值作为对象属性进行访问。例如:
$obj = json_decode($response);
echo "Balance = {$obj->balance}"; // will output 'Balance = 998'
echo "Batch ID = {$obj->batch_id}"; // will output 'Batch ID = 243941208'
echo "Message sender = {$obj->message->sender}"; // will output 'Message sender = TMTLCO'