1

i just want to ask, how can i save my json file from url in some variable. And then, how can i work with it?

normally it go so:

    var jsonOriginal = { name: "Steve", age: 27,  jobTitle: "Program Manager"  };
    alert(person.name);

but now i need json from specific url...with objects inside objects... how can i save this json to var and then call an work with specific object inside othe

it go so, if i use only URL. But i need json inside variable:

    $.getJSON('http://192.168.1.101:8080/mbx/labResults.json', function(data) {
    for(var i=zacetek; i<strani; i+=1){
        var avtorizacija;
        if(data[i].authorizationStatus=="true") avtorizacija = "Da"; else avtorizacija = ""
        $('#myTable2').append("<tr><td><input id='checkbox' type='checkbox' />" + 
                                "<td>" + data[i].id64.labId + "/" + data[i].id64.protocol + "</td>" +
                                "<td>" + data[i].patient.name.toUpperCase() + "</td>" +
                                "<td>" + data[i].patient.kzzNumber + "</td>" +
                                "<td>02.02.2012</td>" +
                                "<td>kri, blato</td>" +
                                "<td>virologija</td>" +
                                "<td>" + avtorizacija +"</td>" +
                                "<td>" + data[i].resultDate +"</td>" +
                                "<td>" + data[i].resultDate +"</td></tr>"
        );
    }
});

thanks

Clem
  • 11,334
  • 8
  • 34
  • 48

1 Answers1

1

You can use a concept of serializing JSON into string and back into objects as explained here: Serializing to JSON in jQuery

Personally I have used: parseJSON and toJSON (can be found in the link), which was very effective and simple to use.

Community
  • 1
  • 1
linuxeasy
  • 6,269
  • 7
  • 33
  • 40