繁体   English   中英

尝试使用JQUERY将结果定位到JSON,但我做错了吗?

[英]Trying to target result in JSON with JQUERY but I'm doing it wrong?

我正在尝试在以下JSON中定位“ workdmark”结果和“ description”结果

{
"count": 1,
"trademarks": [{
    "serialnumber": "85726321",
    "wordmark": "RAIR",
    "code": "GS0351",
    "description": "Regulatory driver log audit reporting and vehicle accident 
     registry for the transportation industry",
    "registrationdate": "06/25/2013"
}]
}

当前,如果我传递“结果”,并且我登录

console.log(`${result.count}`); 

我得到1是正确的。

但是如果我

console.log(`${result.count}`);
console.log(`${result.trademarks}`);
console.log(`${result.trademarks.wordmark}`);
console.log(`${result.trademarks.description}`);

我懂了

1
[object object]
undefined
undefined

我以为自己定位正确? 我搞砸了什么?

您应该获得如下值

console.log(`${result.trademarks[0].wordmark}`);
console.log(`${result.trademarks[0].description}`);

如果您看到商标的结构,则基本上它是数组中的一个对象。 因此,当您处理这些类型的结构时,应在访问数组并首先引用索引位置时对其进行处理。 一旦引用了索引位置,就可以再次使用对象符号。 因此,理想情况下,您应该执行诸如result.trademarks[0].wordmark ,您将获得RAIR

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM