1

i am trying to achieve below json Sorry to say but i am not getting which is issue.

required JSON screen shot with console : https://i.sstatic.net/6fzMx.jpg

var requiredJson = {
        chart: {
            container: "#OrganiseChart-simple"
        },      
        nodeStructure: {text:{name:"Root"},children:[{text:{name:"naresh"},children:[{text:{name:"rahul1"}},{text:{name:"rahul123"}},{text:{name:"kapil1"},children:[{text:{name:"priya12"},children:[{text:{name:"amit12"}}]}]}]},{text:{name:"roshan"}},{text:{name:"Seppl"}},{text:{name:"pankaj1910"}}]}
    };

My try:

my try is giving me this result: https://i.sstatic.net/d1XXD.jpg

my php json when i am using echo to json_encode($tree) :

[{"text":{"name":"Root"},"children":[{"text":{"name":"naresh"},"children":[{"text":{"name":"rahul1"}},{"text":{"name":"rahul123"}},{"text":{"name":"kapil1"},"children":[{"text":{"name":"priya12"},"children":[{"text":{"name":"amit12"}}]}]}]},{"text":{"name":"roshan"}},{"text":{"name":"Seppl"}},{"text":{"name":"pankaj1910"}}]}] ;

//$tree is a php array

var mytry = '<?php echo json_encode($tree); ?>';
 var requiredJson  = {
        chart: {
            container: "#OrganiseChart-simple"
        },

        nodeStructure: mytry 
    };

JS FIDDLE: https://jsfiddle.net/ueo0k9ys/1/

1 Answer 1

2

Remove the quotes around the php output. They are telling the javascript compiler it is a string not array

var mytry = <?php echo json_encode($tree); ?>;
var requiredJson  = {
    chart: {
        container: "#OrganiseChart-simple"
    },

    nodeStructure: mytry 
};
Sign up to request clarification or add additional context in comments.

6 Comments

result not expected : your try giving me this imgur.com/a/D2vzV
with your try nodeStructure is coming as array but it should be an object
So adjust it server side to return what you expect
Not if the structure isn't as expected
ok. I converted my PHP code and now i got this in javascript Object [ Object ] . how can i access second Object ?
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.