【问题标题】:sms response string iteration [closed]短信响应字符串迭代[关闭]
【发布时间】:2017-03-21 06:16:09
【问题描述】:

我有如下字符串接收,这不是正确的json字符串。

{"recipients": 1, "delivery_stats": {"delivered": 0, "bounced": 0, "responses": 0, "pending": 1, "optouts": 0}, "sms": 1, "cost": 1, "send_at": "2017-03-21 05:04:01", "error": {"code": "SUCCESS", "description": "OK"}, "message_id": 9579849}

我需要提取数据来检查某些参数,比如代码等于 SUCCESS 并且还获取 send_at,message_id 的值。

PHP 中最好的方法是什么?能不能转成json字符串进行迭代?

【问题讨论】:

  • 那个字符串不是有效的 JSON 怎么办?
  • 将其传递给 json_decode() 函数
  • a) 您提供的数据 JSON。 b) 到目前为止,您尝试过什么
  • 对不起,我的错误
  • 我粘贴了正确的 json 字符串,而不是应该发布的字符串。无论如何,我已经发现了错误,并且也在其中。感谢您的帮助

标签: php arrays json string


【解决方案1】:

这是一个 json 字符串。 Demo.

<?php
$o = json_decode('{"recipients": 1, "delivery_stats": {"delivered": 0, "bounced": 0, "responses": 0, "pending": 1, "optouts": 0}, "sms": 1, "cost": 1, "send_at": "2017-03-21 05:04:01", "error": {"code": "SUCCESS", "description": "OK"}, "message_id": 9579849}', true);

echo $o['error']['code'];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-23
    • 1970-01-01
    • 2011-01-08
    • 1970-01-01
    • 1970-01-01
    • 2020-01-16
    • 2013-01-29
    • 2014-04-21
    相关资源
    最近更新 更多