简体   繁体   English

Angular 4-通过Key从JSON获取值

[英]Angular 4 - Get Value from JSON by Key

I want to get the value by the key of this json. 我想通过此json的键获取值。 The key is description and i want it in my console.log, i don't really get how to get this value, the filtering before worked fine. 关键是描述,我要在console.log中使用它,我真的不知道如何获得该值,在工作正常之前进行过滤。

{
    "id": "149",
    "description": "Try"
}

Thanks! 谢谢!

First You need to parse it using JSON.parse. 首先,您需要使用JSON.parse对其进行解析。 Then using . 然后使用。 or [] you can access. 或[]您可以访问。 For Ex:- 例如:

var a = '{
    "id": "149",
    "description": "Try"
}'

b = JSON.parse(a) b = JSON.parse(a)

b['description'] or b.description FOr more reference you can study here b ['description']或b.description或您可以在此处学习更多参考

 const dummy = { id : '1', description : 'Wow awesome' }; console.log(dummy.description); //------------------------------------- const descData = dummy.description; console.log(descData); 

variableName['description'] or variableName.description variableName['description']variableName.description

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

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