doulie0178 2016-02-09 19:51
浏览 45
已采纳

想用php [重复]从json结果中获取一个值

This question already has an answer here:

How can i get ID value only

like

$fo = "11890408";

{"success":true,"result":{"success":[{"id":"11890408","device_id":"17183","message":"okey","status":"pending","send_at":1455046054,"queued_at":0,"sent_at":0,"delivered_at":0,"expires_at":1455049654,"canceled_at":0,"failed_at":0,"received_at":0,"error":"","created_at":1455046054,"contact":{"id":"2522330","name":"923336458112","number":"923336458112"}}],"fails":[]}}
</div>
  • 写回答

1条回答 默认 最新

  • dps69208 2016-02-09 19:58
    关注

    Convert the json string to a php data structure and then navigate through the data tree of objects and arrays:

    $json = '{
      "success":true,
      "result":{
        "success[
          {
            "id":"11890408",
            "device_id":"17183",
            "message":"okey",
            "status":"pending",
            "send_at":1455046054,
            "queued_at":0,
            "sent_at":0,
            "delivered_at":0,
            "expires_at":1455049654,
            "canceled_at":0,
            "failed_at":0,
            "received_at":0,
            "error":"",
            "created_at":1455046054,
            "contact":{
              "id":"2522330",
              "name":"923336458112",
              "number":"923336458112"
            }
          }
        ],
        "fails":[]
      }
    }';
    
    $data = json_decode($json);
    $fo = $data->result->success[0]->id;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输