Nevermind. It had nothing to do with the utf8 issue mentioned on the php
site.

The strings were being escaped one to many times. This did the trick.
$json = stripslashes($json);
AJ ONeal


On Fri, Jun 12, 2009 at 4:55 PM, AJ ONeal <[email protected]> wrote:

> I can't figure out how to get json_decode to accept the json I'm feeding it.
> I suspect it has something to do with the character encoding, but I don't 
> have any way to get an error message and be sure.
>
>
> Will any of you please give me some direction?
>
>
> I've been looking at these examples:
> http://docs.jquery.com/Ajax/jQuery.getJSON
> http://www.prodevtips.com/2008/08/15/jquery-json-with-php-json_encode-and-json_decode/
>
> <script language="javascript">
>     var params = Object();
>     params.hash = 'home';
>     params.widget = false;
>     params.menu_loaded = false;
>     dataString = $j.toJSON(params);
>
>
>     $j("#content").text('dstring: ' + dataString);
>     $j.post("controller.php", { data : dataString }, function(res){
>         $j("#content").html(res);
>     });
> </script>
>
>
>
> <?php
>     $json = utf8_encode($_REQUEST['data']);
>     $res = json_decode($json, true);
>     echo '<pre>';
>     echo 'Req: ';
>     var_dump($_REQUEST['data']);
>
>
>     echo 'Res: ';
>     var_dump($res);
>     echo '</pre>';
> ?>
>
> <div id="content">
>     Req: string(63) "{\"hash\": \"home\", \"widget\": false, \"menu_loaded\": 
> false}"
>
>
>     Res: NULL
> </div>
>
>
> AJ ONeal
>
--------------------
BYU Unix Users Group 
http://uug.byu.edu/ 

The opinions expressed in this message are the responsibility of their
author.  They are not endorsed by BYU, the BYU CS Department or BYU-UUG. 
___________________________________________________________________
List Info (unsubscribe here): http://uug.byu.edu/mailman/listinfo/uug-list

Reply via email to