如何从NodeJS JSON中的特定键获取值
问题描述:
{
"id": 83,
"key": "hello",
"en": "Hello",
"mm": "This is greeting",
"created_at": "2016-12-05T10:14:02.928Z",
"updated_at": "2017-01-31T02:57:11.181Z"
}
我正在尝试从NodeJS中的mm
键获取值.我试图获取translation["mm"]
,但它根本不起作用.请帮助我如何从上述数据中获取mm
.
I'm trying to get value from mm
key in NodeJS. I've tried to get translation["mm"]
but it does not work at all. Please help me how to get mm
from above data.
我当前的节点版本是5.11
答
编辑了答案.现在,它适用于上述有问题的对象
您可以使用以下功能访问JSON的键.我已经专门返回了"mm"键.
You can use following function to access the keys of JSON. I have returned 'mm' key specifically.
function jsonParser(stringValue) {
var string = JSON.stringify(stringValue);
var objectValue = JSON.parse(string);
return objectValue['mm'];
}