Get data from a JSON object

I am working on my first project (EVER!) JSON, and I am wondering how to get data from a JSON object. I imported it, and I need to make data entry from the value field and compare it with the user entered. Unfortunately, I can't even figure out how to get data from a JSON object. It seems to be loading successfully, but I cannot reference it. Here is an example JSON download:

{ "films": [{ "label": "34", "value": "34", "currently_streaming": "1", "full_streaming_url": "http://www.url.com", "url": "http://www.url.com"}, { "label": "A Different Color", "value": "A Different Color", "currently_streaming": "1", "full_streaming_url": "http://www.url.php", "url": "http://www.url.com"}] }​ 

And here is the code that loads it. It returns as successful, but I cannot get any data from the JSON object:

  $(document).ready(function(){ $.ajax({ dataType: 'json', beforeSend : function() { console.log('Before Ajax Request Starts !!'); }, success: function(data) { console.log(data); alert("Edddddddd"); $.each(json.films, function(i, object) { $.each(object, function(property, value) { alert(property + "=" + value); }); }); }, error : function(jqXHR, textStatus, errorThrown) { alert("Error occurred: " + errorThrown); }, beforeSend : function() { console.log('Ajax Request Complete !!'); }, url: 'test.php' }); }); 

Of course, I have no idea what I'm doing, and therefore I really appreciate any help!

+4
source share
1 answer

Edit:

 $.each(json.films, function(i, object) 

in

 $.each(data.films, function(i, object) 
+5
source

Source: https://habr.com/ru/post/1435550/


All Articles