json_decode() expects parameter 1 to be string, array given

后端 未结 6 677
清歌不尽
清歌不尽 2021-02-02 14:15

What causes this error in my code?

$query = $this->db->query(\"SELECT * FROM tour_foreign ORDER BY id desc\");
        $data = array();
        foreach ($q         


        
相关标签:
6条回答
  • 2021-02-02 14:33

    here is the solution for similar problem which i was facing while extracting name from user profile facebook json object

    $uname=json_encode($userprof);
    $uname=json_decode($uname);
    echo "Welcome " . $uname -> name  ;
    
    0 讨论(0)
  • 2021-02-02 14:35
    • Make an object

      $obj = json_decode(json_encode($need_to_json));

    • Show data from this $obj

      $obj->{'needed'};

    Reference

    0 讨论(0)
  • 2021-02-02 14:48

    json_decode() is used to decode a json string to an array/data object. json_encode() creates a json string from an array or data. You are using the wrong function my friend, try json_encode();

    0 讨论(0)
  • 2021-02-02 14:49

    I think you want json_encode, not json_decode.

    0 讨论(0)
  • 2021-02-02 14:49

    Set decoding to true

    Your decoding is not set to true. If you don't have access to set the source to true. The code below will fix it for you.

    $WorkingArray = json_decode(json_encode($data),true);
    
    0 讨论(0)
  • 2021-02-02 14:55

    Ok I was running into the same issue. What I failed to notice is that I was using json_decode() instead of using json_encode() so for those who are going to come here please make sure you are using the right function, which is json_encode()

    Note: Depends on what you are working on but make sure you are using the right function.

    0 讨论(0)
提交回复
热议问题