1

私はこのようなデータのセットを持っています

 object(stdClass)#5 (39) { ["id"]=> int(125273716) ["status"]=> object(stdClass)#6 (18) { ["retweeted"]=> ["text"]=> string(28) "1234567" } ["is_translator"]=> bool(false)}

["text"]を取得するにはどうすればよいですか? データが長すぎるため、一部を削除しました。私が欲しいのは ['text'] パラメータだけです。ありがとう

4

4 に答える 4

4

これを試して:

$object->status->text
于 2012-08-22T10:01:27.530 に答える
2

stdClass オブジェクトを多次元配列に変換する関数

<?php

    function objectToArray($d) {
        if (is_object($d)) {
            // Gets the properties of the given object
            // with get_object_vars function
            $d = get_object_vars($d);
        }

        if (is_array($d)) {
            /*
            * Return array converted to object
            * Using __FUNCTION__ (Magic constant)
            * for recursive call
            */
            return array_map(__FUNCTION__, $d);
        }
        else {
            // Return array
            return $d;
        }
    }
?>

使用する:

<?php
echo '<pre>';
var_dump(objectToArray($object));
echo '</pre>';

ソース: http://www.if-not-true-then-false.com/2009/php-tip-convert-stdclass-object-to-multidimensional-array-and-convert-multidimensional-array-to-stdclass-物体/

于 2012-08-22T10:06:24.397 に答える
1

それはオブジェクトです

echo $result->status->text;
于 2012-08-22T10:01:34.307 に答える
0

object(stdClass)#5 (39) { ["id"]=> int(125273716) ["status"]=> object(stdClass)#6 (18) { ["retweeted"]=> ["text"] => 文字列(28) "1234567" } ["is_translator"]=> bool(false)}

as put $res asを試すことができます

$res = $result->status->text;
echo $res;
于 2012-08-22T10:04:38.567 に答える