Stack Exchange
cannot display json with PHP
what's wrong in my code? 
i cant show the data in json...
here's my code..
i'm using oracle with adodb
 function getDados(){
    try{
        $sql = "SELECT * FROM TMP0145705";
        $db = getDB();

        if($db){
            $stmt = $db->Execute($sql);

            $ret = array();
            /*while ($arr = $stmt->FetchRow()) {
                print_r($arr);
                echo "<hr>";
            }*/
            while(!$stmt->EOF){
                $ret[] = $stmt->fields;
                $stmt->MoveNext();
            }
            echo '{"ret": ' . json_encode($ret) . '}';    
        }
        $db = null;
    }catch(Exception $e){
        echo '{"error":{"text":'. $e->getMessage() .'}}';
    }
}

edit:
my json:
{"ret": }

edit:
print_r($ret);
Array ( [0] => Array ( [0] => [MANAGERS] => [1] => 1 [FACTORY] => 1 [2] => 1 [PRODUCT] => 1 [3] => 174))

edit:
 $ret = $stmt->GetArray();

            var_dump($ret);
            echo '{"ret": ' . json_encode($ret) . '}';    

            if( $jret = json_encode($ret) ){ echo "nice"; } else{ echo "Fail"; }

solution!:
my data is in utf-08 and for some reason the json cannot accept that... 
how can i resolve that?

do you need the array inside the array, and have you verified that the query is returning data?

yes.. its returning data.. i test with print_r...

Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.

Can you show us the print_r or var_dump of $ret?

sure... check my edit

I've had this happen if json_encode is not able to successfully encode the array.  Turn on error reporting or just check if json_encode worked: if( $jret = json_encode($ret) ){ echo ... } else{ echo "Fail"; }

dan08... i've checked and is returning "Fail"

Ok, so you have to check the error (it won't be obvious) and figure why your array is giving json_encode a problem. var_dump will be more helpful than print_r for the trouble shooting

i dont have idea... i've changed the code.. but same problem..

pump your json through a json validator and make sure it's valid.
