0

in my d3js example contain [ symbol after children key & working perfectly

{"name": "root",
  "children": [
    {"name": "typeA(1095)",
      "children": [
        {"name": "2010(365)",
          "children": [
            {"name": "january(31)", "value": 31},

http://bl.ocks.org/mbostock/1283663

https://gist.github.com/mbostock/1283663/raw/a05a94858375bd0ae023f6950a2b13fac5127637/readme.json

but i convert a multi-dimensional array using php json_encode there is no [ symbol so when i pass it to d3js example it's not working

$json = array('name'=>'p_date','children'=>array('name'=>'HedCET','value'=>10));

json_encode($json) output

{"name":"p_date","children":{"name":"HedCET","value":10}}

there is no [ symbol after children key, is there any additional option to enable [ symbol in php json_encode ?

OR is there any difference between d3js json file and php json file ?

1
  • Are you passing JSON_FORCE_OBJECT as an option to json_encode? Commented Jan 8, 2014 at 19:45

1 Answer 1

0

In PHP

'children' => array('name' => 'HedCET', 'value' => 10)

is

"children": {"name": "HedCET", "value": 10}

in JSON.

You have forgotten to put another array():

'children' => array( array('name' => 'HedCET', 'value' => 10) )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.