0

以下是我来自 Salesforce 的以下返回查询。如果我尝试这样做,$form_information[0]->Program_Type__c;我会收到以下错误:

不能将 stdClass 类型的对象用作数组

下面是我的以下数组,其中包含一个对象?。我的问题是如何从我的对象中提取 Program_type__c 和 Campus_ID__c 并将其保存到变量中?

print_r($form_information);



Array
    (
        [totalSize] => 1
        [done] => 1
        [records] => Array
            (
                [0] => stdClass Object
                    (
                        [attributes] => stdClass Object
                            (
                                [type] => Program_Instance__c
                                [url] => /services/data/v22.0/sobjects/Program_Instance__c/a0Ji0000001EUk9EAG
                            )

                        [Program_Type__c] => Field Science
                        [Program_Sub_type__c] => 
                        [Campus_ID__c] => a03i0000002DDBjAAO
                    )

            )

    )

var_dump

array(3) {
  ["totalSize"]=>
  int(1)
  ["done"]=>
  bool(true)
  ["records"]=>
  array(1) {
    [0]=>
    object(stdClass)#21 (4) {
      ["attributes"]=>
      object(stdClass)#22 (2) {
        ["type"]=>
        string(19) "Program_Instance__c"
        ["url"]=>
        string(68) "/services/data/v22.0/sobjects/Program_Instance__c/a0Ji0000001EUk9EAG"
      }
      ["Program_Type__c"]=>
      string(13) "Field Science"
      ["Program_Sub_type__c"]=>
      NULL
      ["Campus_ID__c"]=>
      string(18) "a03i0000002DDBjAAO"
    }
  }
}
4

2 回答 2

5

您没有正确遍历对象。

我相信你追求的更像是:

$form_information['records'][0]->Program_Type__c

但是,我鼓励您阅读有关 PHP数组对象属性的介绍。

于 2013-06-12T20:29:35.290 回答
2

试试 $form_information['records'][0]->Program_Type__c;

于 2013-06-12T20:30:06.167 回答