So I have a php page that returns a JSON object in the correct format. like:
[
{
"name":"Users",
"parent":"null",
"children":[ {
"name": "adsd", "parent": "Users", "children": []
}
,
{
"name": "ca", "parent": "Users", "children": []
}
,
{
"name":"ChanakaP",
"parent":"Users",
"children":[ {
"name": "Carlos Puyol rejects Barcelona sporting director role", "parent": "ChanakaP"
}
,
{
"name": "\r\nDiego Costa could leave Atletico Madrid", "parent": "ChanakaP"
}
,
{
"name": "FIFA insist Lionel Messi's award for best men's player was not rigged", "parent": "ChanakaP"
}
,
{
"name": "\r\nReal madrid interested in Van De Beek", "parent": "ChanakaP"
}
,
{
"name": "Hazard scores debut goal", "parent": "ChanakaP"
}
]
}
,
{
"name": "dsd", "parent": "Users", "children": []
}
,
{
"name": "ggggggggggggggggg", "parent": "Users", "children": []
}
,
{
"name":"james123",
"parent":"Users",
"children":[ {
"name": "first post", "parent": "james123"
}
]
}
,
{
"name": "new", "parent": "Users", "children": []
}
,
{
"name": "new123", "parent": "Users", "children": []
}
,
{
"name": "test", "parent": "Users", "children": []
}
]
}
]
I need to take this JSON object and transfer it to a variable in my script in the form of
var obj = k;
where k is the JSON object returned from this URL. I have imported jQuery and tried the $.getJSON method but with no success. So if you have a URL 'ex.com' with the JSON object how would I save it to a variable exactly as it is. So if I copy the output from the url directly to a variable like:
var obj2 = copiedJSON;
my function works as intended but when I use $.getJSON like:
$.getJSON('http://localhost/CS3744-N/GoalLiga/viz', function(json){
obj2 = json;
});
My function returns an error. Does the JSON function change the output that is returned.