未捕获的TypeError:不能使用'in'运算符来搜索'length' [英] Uncaught TypeError: Cannot use 'in' operator to search for 'length' in
问题描述
Uncaught TypeError:无法使用'in'运算符在
中搜索'length'
Uncaught TypeError: Cannot use 'in' operator to search for 'length' in "
这是我尝试对此JSON对象执行 $。每个
时收到的错误:
This is the error I receive when I try to do a $.each
to this JSON object :
{"type":"Anuncio","textos":["Probando esto","$ 20150515"],"submit":"codParameters?___DDSESSIONID\u003d14EA4721A904D6DD71591156996E29F7%3A%2FMobilTest"}
我也试过用stringify做同样的事情,但我收到同样的错误:
I have also tried to do the same with stringify, but I receive the same error:
{\"type\":\"Anuncio\",\"textos\":[\"Probando esto\",\"$ 20150515\"],\"submit\":\"codParameters?___DDSESSIONID\\u003d06CBEC9D1A53616EFF703A8C71FBC2B4%3A%2FMobilTest\"}"
如果我删除参数 ___ DDSESSIONID \\\\=06CBEC9D1A53616EFF703A8C71FBC2B4%3A%2FMobilTest
从对象$ .each正常工作。
If I remove parameters ___DDSESSIONID\\u003d06CBEC9D1A53616EFF703A8C71FBC2B4%3A%2FMobilTest
from the object the $.each works fine.
为什么会发生这种情况?
Why might this be happening?
提前致谢。
推荐答案
运算符中的仅适用于对象。您正在使用字符串。在使用
$。每个
之前,请确保您的值是一个对象。在这种特定情况下,您必须 解析JSON :
The in
operator only works on objects. You are using it on a string. Make sure your value is an object before you using $.each
. In this specific case, you have to parse the JSON:
$.each(JSON.parse(myData), ...);
这篇关于未捕获的TypeError:不能使用'in'运算符来搜索'length'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!