我如何读取该对象的内容

时间:2018-10-13 08:09:32

标签: php web

我正在用PHP开发一个SMS阅读应用程序。我将SMS门户连接到应用程序并接收了SMS。

请帮助我阅读此数组对象并分别获取内容。

array(3) 
{ 
    [0]=> object(stdClass)#14 (8) 
        { 
            ["message"]=> string(3) "G56" 
            ["messageId"]=> int(1) 
            ["recipients"]=> string(11) "94714369777" 
            ["retries"]=> int(1) 
            ["sender"]=> object(stdClass)#15 (1) 
                { 
                    ["alias"]=> string(11) "94710200542" 
                } 
            ["sequenceNum"]=> int(1) 
            ["status"]=> int(1) 
            ["time"]=> string(25) "2018-10-13T10:40:17+05:30" 
        } 
    [1]=> object(stdClass)#16 (8) 
        { 
            ["message"]=> string(4) "A67i" 
            ["messageId"]=> int(1) 
            ["recipients"]=> string(11) "94714369777" 
            ["retries"]=> int(1) 
            ["sender"]=> object(stdClass)#17 (1) 
                { 
                    ["alias"]=> string(11) "94710200542" 
                } 
            ["sequenceNum"]=> int(1) 
            ["status"]=> int(1) 
            ["time"]=> string(25) "2018-10-13T10:40:21+05:30" 
        } 
    [2]=> object(stdClass)#18 (8) 
        { 
            ["message"]=> string(6) "Vhhj99" 
            ["messageId"]=> int(1) 
            ["recipients"]=> string(11) "94714369777" 
            ["retries"]=> int(1) 
            ["sender"]=> object(stdClass)#19 (1) 
                { 
                    ["alias"]=> string(11) "94710200542" 
                } 
            ["sequenceNum"]=> int(1) 
            ["status"]=> int(1) 
            ["time"]=> string(25) "2018-10-13T10:40:24+05:30" 
        } 
} 

2 个答案:

答案 0 :(得分:0)

使用->操作符读取对象值

services.AddIdentity<ApplicationUser>()
            .AddEntityFrameworkStores<AppIdentityDbContext>()
            .AddDefaultTokenProviders();

答案 1 :(得分:0)

这是一个stdObject,因此您可以像访问简单对象一样访问它:

foreach($messages as $sms) {

   $message = $sms->message;
   $messageId = $sms-> messageId;
   $recipients = $sms-> recipients;
   $retries = $sms->retries;
   $sender = $sms->sender['alias'];
   $sequenceNum = $sms->sequenceNum;
   $status = $sms->status;
   $time = $sms->time;

   //...Do your work here
}

如果需要,可以将其转换为数组并访问诸如数组字段之类的属性

$arr = (array) $sms;
$arr['message'];