获取JSON密钥名称 [英] Get JSON key name

查看:64
本文介绍了获取JSON密钥名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下JSON数据: {成功:欢迎你} 我已将其命名为 json 在我的JavaScript代码中。

I have the following JSON data: {"success":"You are welcome"} that I have named json in my JavaScript code.

当我想提醒欢迎你我做 json.success 。所以现在我面临的问题是,如果我想提醒成功,那该怎么办?有没有办法得到它?

When I want to alert You are welcome I do json.success. So now the problem I am facing is that, what about if I want to alert success. Is there any way to get it?

推荐答案


所以现在我面临的问题是,如果我想提醒
成功怎么办?是否需要获取它?

So now the problem I am facing is that, what about if I want to alert success. Is there a need way to get it ?

如果您的对象是

var obj = {"success":"You are welcome"};

您可以获得密钥数组

var keys = Object.keys(obj);

然后将其打印为

console.log( keys[ 0 ] ); //or console.log( keys.join(",") )

var obj = {"success":"You are welcome"};
var keys = Object.keys(obj);
console.log(keys[0]);

这篇关于获取JSON密钥名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆