G
G
gabnastya2018-06-07 17:13:47
JSON
gabnastya, 2018-06-07 17:13:47

Good afternoon! How to read data from json file nodesArray and edgesArray objects and write them to js nodesArray and edgesArray elements? via ajax request?

var nodesArray = [];
        var edgesArray = [];
    ]
            $.getJSON("file.json",function (data) {
                   
                    for(var i=0;i<data.nodesArray.length;i++){
                        nodesArray.append(('nodesArray').append(data.nodesArray[i].id + data.nodesArray[i].label));
                            console.log(data.nodesArray[i].id);
        }
           });


"file.json"

{"nodesArray":[{"id":20,"label":"http:\/\/ido.isu.ru\/ru\/institut\/doc.html"},{" id":21,"label":"http:\/\/ido.isu.ru\/ru\/contacts\/chema.html"},{"id":19,"label":"http:\ /\/ido.isu.ru\/ru\/contacts\/contact.html"},{"id":1,"label":"http:\/\/ido.isu.ru\/ru\/ index.html"},{"id":17,"label":"http:\/\/ido.isu.ru\/ru\/staff\/documenti\/index.html"},{"id" :31,"label":"http:\/\/ido.isu.ru\/ru\/images\/Skulptura"},{"id":8,"label":"http:\/\/ido .isu.ru\/ru\/institut\/index.html"},{"id":12,"label":"http:\/\/ido.isu.ru\/ru\/education\/PP \/"},{"id":37,"label":"http:\/\/ido.isu.ru\/ru\/announces\/announceitem.html?action=show&id=1295"},{"id":44,"label":"http:\/\/ ido.isu.ru\/ru\/staff\/teacher\/"},{"id":7,"label":"http:\/\/ido.isu.ru\/ru\/"},
{"id":29,"label":"http:\/\/ido.isu.ru\/ru\/announces\/announceitem.html?action=show&id=1153"}],"
edgesArray":[{"arrows":"to","from":20,"to":20},{"arrows":"to","from":20,"to":3},{" arrows":"to","from":20,"to":21},{"arrows":"to","from":20,"to":19},{"arrows":"to" ,"from":20,"to":7},{"arrows":"to","from":20,"to":9},{"arrows":"to","from":20 ,"to":1},{"arrows":"to","from":20,"to":8},{"arrows":"to","from":20,"to":2 },{"arrows":"to","from":20,"to":10},{"arrows":"to","from":20,"to":11},{"arrows" :"to","from":20,"to":5},{"arrows":"to","from":20,"to":6},{"arrows":"to","from" :20,"to":14},{"arrows":"to","from":20,"to":13},{"arrows":"to","from":20,"to" :4},{"arrows":"to","from":20,"to":16},{"arrows":"to","from":36,"to":20},{" arrows":"to","from":36,"to":3},{"arrows":"to","from":36,"to":21},{"arrows":"to" ,"from":36,"to":19},{"arrows":"to","from":36,"to":7},{"arrows":"to","from":36 ,"to":1},{"arrows":"to","from":36,"to":23},

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nick Sdk, 2018-06-07
@lidacriss

Like this?

var nodesArray = [];
var edgesArray = [];
$.getJSON("file.json", function(json){
  nodesArray = json.nodesArray;
  edgesArray = json.edgesArray;
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question