Uncaught TypeError: cannot use the 'in' operator to search for 'length' in

Uncaught TypeError: cannot use the 'in' operator to search for 'length' in '

This is the error I get when I try to make $.each for this JSON object:

 {"type":"Anuncio","textos":["Probando esto","$ 20150515"],"submit":"codParameters?___DDSESSIONID\u003d14EA4721A904D6DD71591156996E29F7%3A%2FMobilTest"} 

I also tried to do the same with stringify, but I get the same error:

 {\"type\":\"Anuncio\",\"textos\":[\"Probando esto\",\"$ 20150515\"],\"submit\":\"codParameters?___DDSESSIONID\\u003d06CBEC9D1A53616EFF703A8C71FBC2B4%3A%2FMobilTest\"}" 

If I remove the ___DDSESSIONID\\u003d06CBEC9D1A53616EFF703A8C71FBC2B4%3A%2FMobilTest from the object, then $ .each works fine.

Why can this happen?

Thank you in advance.

+73
json javascript jquery getjson
May 15 '15 at
source share
3 answers

The in operator only works with objects. You use it on a string. Before using $.each make sure your value is an object. In this particular case, you should parse JSON :

 $.each(JSON.parse(myData), ...); 
+177
May 15 '15 at 10:13
source share

maybe you forgot to add the parameter dataType: 'json' to your $ .ajax

 $.ajax({ type: "POST", dataType: "json", url: url, data: { get_member: id }, success: function( response ) { //some action here }, error: function( error ) { alert( error ); } }); 
+3
Feb 09 '19 at 14:43
source share

what happens if i still have the same error while loading via jQuery.getJSON ()

-one
Apr 26 '19 at 0:17
source share



All Articles