嘿我在尝试集成API时遇到API问题...
我有这段代码:
$deleteOld = $facepp->execute('/person/delete', array('person_name' => $id));
$response = $facepp->execute('/person/create', array('person_name' => $id));
print_r($response);
echo $response['body']['person_id'];
print_r输出
Array
(
[http_code] => 200
[request_url] => http://apius.faceplusplus.com//person/create
[body] => {
"added_face": 0,
"added_group": 0,
"person_id": "00c812cbd9c763a6dae36a48bc54b855",
"person_name": "3824",
"tag": ""
}
)
我想要返回person_id,但我得到的只是" {"
解决方案:
$response = $facepp->execute('/person/create', array('person_name' => $id));
print_r($response);
$response = json_decode($response['body'], true);
echo $response['person_id'];
答案 0 :(得分:0)
你必须使用json_decode()函数然后它将转换为数组
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($json));
答案 1 :(得分:0)
解决方案:
$response = $facepp->execute('/person/create', array('person_name' => $id));
print_r($response);
$response = json_decode($response['body'], true);
echo $response['person_id'];