2014-09-23 87 views
0

轉換的數據我有一個對象響應類型無法獲取陣列從對象

FirstGivingCreditCardDonationResponse Object ([transactionId:FirstGivingCreditCardDonationResponse:private] => a-10d28597b9dc524bae6a02 
[rawResponse:FirstGivingCreditCardDonationResponse:private] => a-10d28597b9dc524bae6a020 
[responseCode:FirstGivingCreditCardDonationResponse:private] => 201) 

轉換成陣列之後變得

Array ([FirstGivingCreditCardDonationResponsetransactionId] => a-b15ed981602d994d87718e [FirstGivingCreditCardDonationResponserawResponse] => a-b15ed981602d994d87718e0 [FirstGivingCreditCardDonationResponseresponseCode] => 201) 

當我想從陣列這些值它顯示

A PHP Error was encountered 
Severity: Notice 

Message: Undefined index: FirstGivingCreditCardDonationResponseresponseCode 

Filename: controllers/campaign.php 

Line Number: 132 

回答

0

大概你在這裏使用這個類:https://github.com/firstgiving/FirstGiving-PHP-SDK/blob/master/src/FirstGivingCreditCardDonationResponse.php

我不會將對象轉換成一個數組,只是通過公共方法訪問其私人屬性:

$ResponseObject::getTransactionID(); 
$ResponseObject::getRawResponse(); 
$ResponseObject::getResponseCode(); 

您可能需要包括頭,以定義類與它

工作
+0

我在哪裏得到$ ResponseObject? – Algobasket 2014-09-23 09:05:01

+0

對不起,'$ ResponseObject'只是假設你將它作爲響應接收到的對象分配給它的PHP變量。我需要更多的背景,真正幫助您更加有 – GroovyCarrot 2014-09-23 09:10:51

+0

一個PHP錯誤遇到 嚴重性:注意 消息:未定義的屬性:活動:: $的transactionId 文件名:firstgiving/FirstGivingCreditCardDonationResponse.php 行號:42 – Algobasket 2014-09-23 09:15:52