【发布时间】:2019-04-23 21:49:18
【问题描述】:
我正在使用 Infobip SMS API 将 SMS 发送到单个和多个目的地,但是我收到的送达报告和 SMS 日志对我的用户来说是压倒性的,我只想显示每个发送的 SMS 的部分报告。这是我的用户获得的 JSON 报告示例,我只需要报告的 groupName 部分
{
"results":[
{
"bulkId":"bafdeb3d-719b-4cce-8762-54d47b40f3c5",
"messageId":"07e03aae-fabc-44ad-b1ce-222e14094d70",
"to":"41793026727",
"from":"InfoSMS",
"text":"Test SMS.",
"sentAt":"2015-02-23T17:41:11.833+0100",
"doneAt":"2015-02-23T17:41:11.843+0100",
"smsCount":1,
"mccmnc":"22801",
"price":{
"pricePerMessage":0.01,
"currency":"EUR"
},
"status":{
"groupId":3,
"groupName":"DELIVERED",
"id":5,
"name":"DELIVERED_TO_HANDSET",
"description":"Message delivered to handset"
},
"error":{
"groupId":0,
"groupName":"OK",
"id":0,
"name":"NO_ERROR",
"description":"No Error",
"permanent":false
}
},
{
"bulkId":"06479ba3-5977-47f6-9346-fee0369bc76b",
"messageId":"1f21d8d7-f306-4f53-9f6e-eddfce9849ea",
"to":"41793026727",
"from":"InfoSMS",
"text":"Test SMS.",
"sentAt":"2015-02-23T17:40:31.773+0100",
"doneAt":"2015-02-23T17:40:31.787+0100",
"smsCount":1,
"mccmnc":"22801",
"price":{
"pricePerMessage":0.01,
"currency":"EUR"
},
"status":{
"groupId":3,
"groupName":"DELIVERED",
"id":5,
"name":"DELIVERED_TO_HANDSET",
"description":"Message delivered to handset"
},
"error":{
"groupId":0,
"groupName":"OK",
"id":0,
"name":"NO_ERROR",
"description":"No Error",
"permanent":false
}
}
]
}
【问题讨论】:
-
我用 foreach 循环尝试了答案,但是当执行达到值 price,我想是因为它是另一个数组
-
您需要将
true放在第二个参数中。$arr = json_decode($json, true)导致将 json 字符串转换为数组。然后循环通过$arr['results']
标签: php json infobip infobip-api