Welcome Guest, Not a member yet? Register   Sign In
json_decode, strings, and query results
#1

[eluser]CodeIgniterNewbie[/eluser]
Code:
// Example 1: string is surrounded with double quotes, which is what JSON needs
$a = '"Hello world"';
echo('$a JSON decode is: ' . json_decode($a)); // displays: Hello world

echo('<br/>');

// Example 2: string is not surrounded with double quotes; json_decode *should* ignore this
$b = "Hello world";
echo('$b JSON decode is: ' . json_decode($b)); // displays nothing

I need to return the result of a DB query as a JSON string. When I query the model, I get a result similar to Example 2 above (strings are not surrounded with double quotes; the double quotes are just part of PHP's representation to indicate the value is a string). Thus, the string values from my DB query results disappear when when I json_decode them. (Oddly, though, this "disappearing act" does not occur on a fellow developer's local machine.)

What's going on here? How do I effectively convert my query results to JSON string?


Messages In This Thread
json_decode, strings, and query results - by El Forum - 06-14-2010, 06:01 PM
json_decode, strings, and query results - by El Forum - 06-14-2010, 09:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB