jQuery JSON parse via $.each - Cannot get length of undefined

MikeF

I am trying to parse a JSON response from a PHP call.

The returned data is in JSON format, as below:

{"success":true,
 "venues":
      [
          {"id":237,"title":"Country House Hotel and Restaurant","thumb_image":"thumb_combe-house-buttercups_3617067271.jpg","description":"","subType":1},
          {"id":579,"title":"Abode Exeter","thumb_image":"wvs.jpg","description":"","subType":0},
          {"id":484,"title":"Anran Luxury Boutique","thumb_image":"wvs.jpg","description":"","subType":0}
      ]
}

However, when I try to use the $.each function to loop over it, it is returning an error Uncaught TypeError: Cannot read property 'length' of undefined.

A snippet of the code I am using to perform the $.each loop is below.

$.each(data.venues, function() {
    $.each(this, function(k, v) {
        alert(k + ' ' + v);
    });
});
cari

it works as expected, if you parseJSON the data.

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(function() {

var data = $.parseJSON('{"success":true,"venues":[{"id":237,"title":"Country House Hotel and Restaurant","thumb_image":"thumb_combe-house-buttercups_3617067271.jpg","description":"","subType":1},{"id":579,"title":"Abode Exeter","thumb_image":"wvs.jpg","description":"","subType":0},{"id":484,"title":"Anran Luxury Boutique","thumb_image":"wvs.jpg","description":"","subType":0}]}');

$.each(data.venues, function() {
                $.each(this, function(k, v) {
                    alert(k + ' ' + v);
                });
            });

});
</script>
</head>
<body>

Demo: http://pascha.org/test/4.php

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jQuery parse json and get element, getting undefined

From Dev

jQuery - Cannot parse json

From Dev

Cannot read property 'length' of undefined jquery

From Dev

Uncaught TypeError: Cannot read property 'length' of undefined - JSON/JQUERY/Data.error

From Dev

Uncaught TypeError: Cannot read property 'length' of undefined - JSON/JQUERY/Data.error

From Dev

Get element tag name and length with Jquery each

From Dev

Get element tag name and length with Jquery each

From Dev

Cannot get the length of JSON array in javascript

From Dev

JQuery Datatable Error "Cannot read property 'length' of undefined"

From Dev

Uncaught TypeError: Cannot read property 'length' of undefined JQUERY autocomplete

From Dev

JQuery Datatable Error "Cannot read property 'length' of undefined"

From Dev

jquery error uncaught typeerror: cannot read property 'length' of undefined

From Dev

Cannot Parse JSON data With jQuery.parseJSON

From Dev

.ajax JSON TypeError: Cannot read property 'length' of undefined

From Dev

"Cannot read property 'length' of undefined" - trying to get children of a classname

From Dev

Parse - Uncaught TypeError: Cannot read property 'get' of undefined

From Dev

JSON array get length using jQuery or javascript

From Dev

Jquery, Cannot get the each li in Div

From Dev

cannot read property'length' of undefined

From Dev

Getting undefined variable in Instagram JSON feed via jQuery

From Dev

JSON node in jquery, Uncaught TypeError: Cannot read property '0' of undefined

From Dev

Jquery json : Uncaught TypeError: Cannot read property 'xx' of undefined

From Dev

Cannot parse JSON array

From Dev

Cannot parse JSON?

From Dev

Cannot parse JSON response

From Dev

Get the object length in angularjs is undefined

From Dev

Nested JSON Array throwing "Uncaught TypeError: Cannot read property 'length' of undefined" when trying to iterate through

From Dev

Uncaught TypeError: Cannot read property 'length' of undefined in line chart with json data

From Dev

Why do I get "Uncaught TypeError: Cannot read property 'length' of undefined(…)"?

Related Related

  1. 1

    jQuery parse json and get element, getting undefined

  2. 2

    jQuery - Cannot parse json

  3. 3

    Cannot read property 'length' of undefined jquery

  4. 4

    Uncaught TypeError: Cannot read property 'length' of undefined - JSON/JQUERY/Data.error

  5. 5

    Uncaught TypeError: Cannot read property 'length' of undefined - JSON/JQUERY/Data.error

  6. 6

    Get element tag name and length with Jquery each

  7. 7

    Get element tag name and length with Jquery each

  8. 8

    Cannot get the length of JSON array in javascript

  9. 9

    JQuery Datatable Error "Cannot read property 'length' of undefined"

  10. 10

    Uncaught TypeError: Cannot read property 'length' of undefined JQUERY autocomplete

  11. 11

    JQuery Datatable Error "Cannot read property 'length' of undefined"

  12. 12

    jquery error uncaught typeerror: cannot read property 'length' of undefined

  13. 13

    Cannot Parse JSON data With jQuery.parseJSON

  14. 14

    .ajax JSON TypeError: Cannot read property 'length' of undefined

  15. 15

    "Cannot read property 'length' of undefined" - trying to get children of a classname

  16. 16

    Parse - Uncaught TypeError: Cannot read property 'get' of undefined

  17. 17

    JSON array get length using jQuery or javascript

  18. 18

    Jquery, Cannot get the each li in Div

  19. 19

    cannot read property'length' of undefined

  20. 20

    Getting undefined variable in Instagram JSON feed via jQuery

  21. 21

    JSON node in jquery, Uncaught TypeError: Cannot read property '0' of undefined

  22. 22

    Jquery json : Uncaught TypeError: Cannot read property 'xx' of undefined

  23. 23

    Cannot parse JSON array

  24. 24

    Cannot parse JSON?

  25. 25

    Cannot parse JSON response

  26. 26

    Get the object length in angularjs is undefined

  27. 27

    Nested JSON Array throwing "Uncaught TypeError: Cannot read property 'length' of undefined" when trying to iterate through

  28. 28

    Uncaught TypeError: Cannot read property 'length' of undefined in line chart with json data

  29. 29

    Why do I get "Uncaught TypeError: Cannot read property 'length' of undefined(…)"?

HotTag

Archive