将带有SubTree的JSON存储到PHP变量中

我有一个从CRM获取的JSON对象,用于在数据库中进行记录。从CRM服务返回的响应当前如下所示:

{
  "data": [
    {
      "Owner": {
        "name": "Shrihari Prakash","id": "Some ID"
      },"Email": "example@example.com","$currency_symbol": "$","Other_Phone": null,"Mailing_State": null,"Other_State": null,"Other_Country": null,"Last_activity_Time": "2019-12-05T17:14:50+05:30","Department": null,"$state": "save","$process_flow": false,"Assistant": null,"Mailing_Country": null,"id": "Some ID","$approved": true,"Reporting_To": null,"$approval": {
        "delegate": false,"approve": false,"reject": false,"resubmit": false
      },"Other_City": null,"Created_Time": "2019-12-05T16:24:33+05:30","$editable": true,"DoctorID": #SomeID,"Home_Phone": null,"Created_By": {
        "name": "Shrihari Prakash","Secondary_Email": null,"Description": null,"Mailing_Zip": null,"$review_process": null,"Twitter": null,"Other_Zip": null,"Mailing_Street": null,"Salutation": null,"First_Name": null,"Full_Name": "Shrihari Prakash","Asst_Phone": null,"Modified_By": {
        "name": "Shrihari Prakash","$review": null,"Skype_ID": null,"Phone": null,"Email_Opt_Out": false,"Modified_Time": "2019-12-05T17:14:50+05:30","Date_of_Birth": null,"Mailing_City": null,"Title": null,"Other_Street": null,"Mobile": null,"Last_Name": "Shrihari Prakash","Lead_Source": null,"Tag": [],"Fax": null
    }
  ],"info": {
    "per_page": 200,"count": 1,"page": 1,"more_records": false
  }
}

我尝试访问的字段是“全名”字段。我尝试访问的代码:

$result = curl_exec($ch);
$parsed = json_decode($result,true);
echo $parsed->Full_Name;
curl_close($ch);

我遇到的错误:

  

通知:尝试获取非对象的属性   C:\ xampp \ htdocs \ Project \ crmFunctions.php在第88行

hjghjgdf54 回答:将带有SubTree的JSON存储到PHP变量中

您可以生成为$parsed['data'][0]['Full_Name']

您在"DoctorID": #SomeID,的示例json中也存在错误,只需更正它,您将得到输出

$array = '{
  "data": [
    {
      "Owner": {
        "name": "Shrihari Prakash","id": "Some ID"
      },"Email": "example@example.com","$currency_symbol": "$","Other_Phone": null,"Mailing_State": null,"Other_State": null,"Other_Country": null,"Last_Activity_Time": "2019-12-05T17:14:50+05:30","Department": null,"$state": "save","$process_flow": false,"Assistant": null,"Mailing_Country": null,"id": "Some ID","$approved": true,"Reporting_To": null,"$approval": {
        "delegate": false,"approve": false,"reject": false,"resubmit": false
      },"Other_City": null,"Created_Time": "2019-12-05T16:24:33+05:30","$editable": true,"DoctorID": "#SomeID","Home_Phone": null,"Created_By": {
        "name": "Shrihari Prakash","Secondary_Email": null,"Description": null,"Mailing_Zip": null,"$review_process": null,"Twitter": null,"Other_Zip": null,"Mailing_Street": null,"Salutation": null,"First_Name": null,"Full_Name": "Shrihari Prakash","Asst_Phone": null,"Modified_By": {
        "name": "Shrihari Prakash","$review": null,"Skype_ID": null,"Phone": null,"Email_Opt_Out": false,"Modified_Time": "2019-12-05T17:14:50+05:30","Date_of_Birth": null,"Mailing_City": null,"Title": null,"Other_Street": null,"Mobile": null,"Last_Name": "Shrihari Prakash","Lead_Source": null,"Tag": [],"Fax": null
    }
  ],"info": {
    "per_page": 200,"count": 1,"page": 1,"more_records": false
  }
}';



$parsed = json_decode($array,true);
echo $parsed['data'][0]['Full_Name'];
本文链接:https://www.f2er.com/2958858.html

大家都在问