php - json_decode returning blank -
i working on facebook app. have stored values in database in json format.
when fetching value on target page , trying display value follow :
$sql = mysql_query("select * `beforepublish` `tabid` = '$page_id'") or die(mysql_error()); $sql = mysql_fetch_assoc($sql);  $contest_id = $sql['contestid']; $temp_id = $sql["tempid"]; $value = $sql["values"]; $returnvalue = json_decode($value); echo "<pre>"; print_r($returnvalue); echo "</pre>";   here value of
$value = {"image":"upload_1182341221.jpg","conttxt":"get chance win samsung galaxy tab "}
and getting $returnvalue blank.
but when try :
$returnvalue = json_decode('{"image":"upload_1182341221.jpg","conttxt":"get chance win samsung galaxy tab "}'); echo "<pre>"; print_r($returnvalue); echo "</pre>";   then $returnvalue returning :
stdclass object (     [image] => upload_1182341221.jpg     [conttxt] => chance win samsung galaxy tab  )   so guys, please me, why getting blank value in previous case ?
edit
vardump($value) returning :
string '{"image":"upload_1182341221.jpg","conttxt":"get chance win samsung galaxy tab     "}' (length=86)      
string '{"image":"upload_1182341221.jpg","conttxt":"get chance win samsung galaxy tab     "}' (length=86)   there problem. linebreak , tab. should like:
string '{"image":"upload_1182341221.jpg","conttxt":"get chance win samsung galaxy tab"}' (length=84)   this why var_dump() outputs length, can validate against unwanted/invisible characters.
you can store line breaks in javascript strings \n.
 json_encode() automatically.
this applies escape sequences (commonly used ones \n, \r, \t , \b).
Comments
Post a Comment