【问题标题】:string element of array is not able to access after json decodejson解码后数组的字符串元素无法访问
【发布时间】:2021-06-30 05:47:46
【问题描述】:

这是我的解码数组代码

$transfer = '{"type": "BALANCE","status": "REJECTED"}'; $json = json_decode($transfer); echo $json->status;

它没有显示状态值。

如果我将状态更改为整数值。

$transfer = '{"type": "BALANCE","status": "1234"}';

然后它显示状态值为 1234。

如果是字符串格式,如何显示状态值。

【问题讨论】:

    标签: json decode


    【解决方案1】:

    一切正常

    <?php 
    
    $transfer = '{"type": "BALANCE","status": "REJECTED"}'; 
    $json = json_decode($transfer); 
    echo $json->status; //displays REJECTED
    
    ?>
    

    【讨论】:

    • 它没有返回任何东西..我不明白这个问题..
    • echo $json-&gt;status 在我的末尾显示 REJECTED。
    • 标签之间添加您的代码w3schools.com/php/phptryit.asp?filename=tryphp_compiler 并查看结果
    • 我已经尝试了所有这些东西..它在项目之外工作正常..我得到的这个传输数据来自明智的传输 api..我很困惑天气数据格式错误或什么还有吗?
    • 如果你从 api 获取数据。在 json 解码之前尝试JSON.stringify($transfer)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-09
    • 2018-07-02
    相关资源
    最近更新 更多