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

问题描述 投票:0回答:1

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

{
  "data": [
    {
      "Owner": {
        "name": "Shrihari Prakash",
        "id": "Some ID"
      },
      "Email": "[email protected]",
      "$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",
        "id": "Some ID"
      },
      "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",
        "id": "Some ID"
      },
      "$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
  }
}

我尝试访问的字段是'Full_Name'字段。我尝试访问的代码:

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

我得到的错误:

Notice:试图获取非对象的属性C:\ xampp \ htdocs \ Project \ crmFunctions.php,第88行

php json crm
1个回答
0
投票

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

您在"DoctorID": #SomeID,的示例json中也有错误,只需对其进行更正,您将获得输出

$array = '{
  "data": [
    {
      "Owner": {
        "name": "Shrihari Prakash",
        "id": "Some ID"
      },
      "Email": "[email protected]",
      "$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",
        "id": "Some ID"
      },
      "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",
        "id": "Some ID"
      },
      "$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'];
© www.soinside.com 2019 - 2024. All rights reserved.