0

I am new using a json file and i wanna put the file into a text variable in javascript to run a function not in a object....
I have been trying something like this.. but nothing...

var jqxhr = $.getJSON( "json/test.json", function() {
                  console.log( "success" );
                })

alert (getDepth(jqxhr));

1 Answer 1

1

What you are going to want to do is retrieve the contents of the JSON file within your success callback -

var jqxhr = $.getJSON( "json/test.json", function(jsonData) { 
  console.log( jsonData );
})

Note that the resulting variable (jsonData) does not in fact contain text - it contains a JavaScript object.

Sign up to request clarification or add additional context in comments.

2 Comments

This is misleading. It implies that receivedData will be available for a statement that could be added to line 5.
I wan to get something like this from the file, the data in a variable. ' var input = { "name": "positive", "children": [{ "name": "product service", "children": [{ "name": "price", "children": [{ "name": "cost", "size": 8 }] }, { "name": "quality", "children": [{ "name": "messaging", "size": 4 }] }] }] }'

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.