Search code examples
phpjsonsencha-touch-2

JSON : true value come with quote


I want to output a nested JSON array for my Sencha-Touch app, and I have to signalize the leaf nodes.

Heres is the right syntax :

  {
      "text": "Random",
      "leaf": true
  }

I create my array in PHP from server-side, here is the line where i'm adding the leaf info :

$myRow['leaf'] = 'true';     

Unfortunately it's not that simple, the output, after json-encoding my array is :

{
    "text": "Random",
    "leaf":"true"
}

The quotes around true are problematic because Sencha Touch don't recognize the boolean value.

I tried without the quotes around true in my PHP file but then i get

"leaf" : "1"

in the JSON callback...

I tried some other tricks but always the same issue.

Someone had the same problem ?

Thank you in advance.


Solution

  • It works with

    $myRow['leaf'] = true;
    

    But I was using utf8_encode() so it changed the true into "1".