0

iContact API をいじっていて、問題が発生しています。API を使用して連絡先を作成した後、最新の応答を取得しようとしているので、contactId を解析して、その連絡先にメッセージを送信したり、リストに追加したりできます。

// adds new client to iContact
var_dump($oiContact->addContact('usersemailaddress@here.com', null, null, 'Joe', 'Smith', null, '123 Somewhere Ln', 'Apt 12', 'Somewhere', 'NW', '12345', '123-456-7890', '123-456-7890', null));

// Gets last response (results are showing below
$obj = $oiContact->getLastResponse();

$obj 変数を出力すると、これが得られます

{"contacts":[{"contactId":"1009090","prefix":"","firstName":"Joe","lastName":"Smith","suffix":"","street":"123 Somewhere Ln","street2":"Apt 12","city":"Somewhere","state":"NW","postalCode":"12345","phone":"123-456-7890","fax":"123-456-7890","business":"","email":"usersemailaddress@here.com","createDate":"2014-04-24 01:31:59","bounceCount":"","status":"normal"}]}

    //decode json object and echo it
    $data = json_decode($obj,TRUE);
    echo $data->contacts[0]->contactId;

エラー メッセージ: 通知: 行 24 の ...(パス)... で非オブジェクトのプロパティを取得しようとしています

私は他の投稿を見て、同じ解決策のいくつかを複製しようとしましたが、何もうまくいかないようでした. 高度なヘルプをありがとう。

4

1 に答える 1

3

オブジェクト メソッドでアクセスする場合は、json_decode 関数のパラメーター リストから TRUE を削除します。TRUE を渡すと、配列が返されます。

$data = json_decode($obj);

それ以外の場合は、このようにアクセスする必要があります。

//decode json object and echo it
$data = json_decode($obj,TRUE);
echo $data['contacts'][0]['contactId'];
于 2014-04-24T07:33:14.507 に答える