我正在创建一个 API,但最终服务器以包含 RECORD 属性的 JSON 格式向我发送信息:
{
"RECORD": [{
"@ID": "1",
"FULLNAME": "*\"* **** ****",
"PHONE": "*******",
"CELLULAR": "********",
"LOGIN_STATUS": "*",
"LOGIN_STATUS_TEXT": "****",
"STUDENT_ACADEMIC_YEAR": "",
"STUDENT_DEPARTMENT": "",
"STUDENT_SPECIALITY": "",
"STUDENT_PHONE": "",
"STUDENT_CELLULARPHONE": "",
"STUDENT_ADDRESS": " *",
"STUDENT_EMAIL": "",
"STUDENT_STATUS": "",
"STUDENT_ID": "*",
"TEACHER_ID": "*******",
"CURRENTYEAR": "****",
"TOKEN": "*************",
"CURRENTFULLYEAR": "****"
}]
}
如何从内部属性中提取数据?我使用以下命令解码:
$jsonRestData=json_decode($jsonRestData2, true);
我试过了:
$request_json["attributes"] = array(
"userid" => str_replace(" ","",$user_uid),
"fullname" => $jsonRestData->FULLNAME,
"email" => $jsonRestData->STUDENT_EMAIL,
"role" => $jsonRestData->STUDENT_STATUS,
"year" => $jsonRestData->STUDENT_ACADEMIC_YEAR,
"department" => $jsonRestData->STUDENT_DEPARTMENT,
"speciality" => $jsonRestData->STUDENT_SPECIALITY
);
我也试过:
$request_json["attributes"] = array(
"userid" => str_replace(" ","",$user_uid),
"fullname" => $jsonRestData->RECORD->FULLNAME,
"email" => $jsonRestData->RECORD->STUDENT_EMAIL,
"role" => $jsonRestData->RECORD->STUDENT_STATUS,
"year" => $jsonRestData->RECORD->STUDENT_ACADEMIC_YEAR,
"department" => $jsonRestData->RECORD->STUDENT_DEPARTMENT,
"speciality" => $jsonRestData->RECORD->STUDENT_SPECIALITY
);
对于第一个示例,我收到一个错误:未定义的属性:stdClass::$FULLNAME
第二个我收到一个错误:试图获取非对象的属性
FFIVE
慕容3067478