jQuery无法在使用Ajax响应时使用'in'运算符搜索'length'

时间:2019-02-24 15:10:10

标签: json ajax asp.net-mvc

  

[{“ ContainerNo”:“ FCIU3554053”,“ Size”:20,“ SealNo”:“ 172003”,“ Weight”:25209.00},{“ ContainerNo”:“ TEMU5422909”,“ Size”:20,“ SealNo“:” 164169“,” Weight“:25400.00}]

input_sentence = input-sequence.split("a")
if input_sentence.startswith('a') and input_sentence.endswith('a'):
    print('yes')

ex = 'abbabbabbabba'

def check_recursive(character, last_characters):
    sequence = character
    for i in reversed(range(0,len(last_characters))):
        if last_characters[i] == character:
            sequence += last_characters[i]
        else:
        return sequence

outputs = []
for i in reversed(range(1, len(ex))):
    output = check_recursive(ex[i], ex[:i])
    if output != ex[i]:
        outputs.append(output)
if len(set(outputs)) == 1:
    print("Only one type of sequence.")

我遇到错误Uncaught TypeError:无法使用'in'运算符搜索'length'。我很困扰。我在执行时遇到相同的错误-parsedJson.Count。

1 个答案:

答案 0 :(得分:0)

首先,您有where foo in (Null, 0)个对象:

Array

请注意:var foo = '[{"ContainerNo":"FCIU3554053","Size":20,"SealNo":"172003","Weight":25209.00},{"ContainerNo":"TEMU5422909","Size":20,"SealNo":"164169","Weight":25400.00}]'; (用单引号引起来)可以使用string进行辩解,否则,如果响应已经是JSON.parse,则无需解析。

Array

输出:

var parsed = JSON.parse(foo)

// iterate over your array
for(i = 0; i < parsed.length; i ++){
    console.log(`Container No: ${parsed[i].ContainerNo}, Seal No: ${parsed[i].SealNo} `);
}

如果要使用Array.forEach

Container No: FCIU3554053, Seal No: 172003
Container No: TEMU5422909, Seal No: 164169

输出:

parsed.forEach( i => console.log(`Container No: ${i.ContainerNo}, Seal No: ${i.SealNo} `));