duanbai1027 2017-04-30 14:13
浏览 54
已采纳

读取数组并将参数设置为特定值

I have a parameter $return.

When I set "print_r($return);" I get the following:

{"allresponses":"{\"adm_big_picture\":null,\"adm_group\":null,\"adm_group_message\":null,\"adm_large_icon\":null,\"adm_small_icon\":null,\"adm_sound\":null,\"amazon_background_data\":false,\"android_accent_color\":null,\"android_group\":null,\"android_group_message\":null,\"android_led_color\":null,\"android_sound\":null,\"android_visibility\":null,\"app_id\":\"XXXX\",\"big_picture\":null,\"buttons\":null,\"canceled\":false,\"chrome_big_picture\":null,\"chrome_icon\":null,\"chrome_web_icon\":\"\",\"chrome_web_image\":\"\",\"content_available\":false,\"contents\":{\"en\":\"This is a new message.\"},\"converted\":0,\"data\":null,\"delayed_option\":\"immediate\",\"delivery_time_of_day\":\"4:00 PM\",\"errored\":0,\"excluded_segments\":[],\"failed\":0,\"firefox_icon\":\"\",\"headings\":{\"en\":\"New Message\"},\"id\":\"12\",\"include_player_ids\":null,\"included_segments\":[\"All\"],\"ios_badgeCount\":null,\"ios_badgeType\":null,\"ios_category\":null,\"ios_sound\":null,\"isAdm\":false,\"isAndroid\":false,\"isChrome\":false,\"isChromeWeb\":true,\"isFirefox\":true,\"isIos\":false,\"isSafari\":true,\"isWP\":false,\"isWP_WNS\":false,\"large_icon\":null,\"priority\":null,\"queued_at\":1492523636,\"remaining\":0,\"send_after\":1492523636,\"small_icon\":null,\"successful\":3,\"tags\":null,\"filters\":null,\"template_id\":null,\"ttl\":null,\"url\":\"\",\"web_buttons\":null,\"wp_sound\":null,\"wp_wns_sound\":null}"}

I would like to take specific values and assign them to a parameter, for example to take value of app_id and set it as a value of $appId so when I do echo $appId, the value xxxx is printed on screen.

Have tried using the following, but not returning results:

$obj= json_decode($return);
$appId = $obj->allresponses->app_id;
echo $appId;

Can someone guide me please?

Thanks :)

  • 写回答

2条回答 默认 最新

  • douyanzhou1450 2017-04-30 14:29
    关注

    I need to decode the json object twice, i.e.:

    $obj = json_decode($return);
    $obj = json_decode($obj->allresponses);
    $appId = $obj->app_id;
    echo $appId;
    # XXXX
    

    PHP Demo

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?