下面是我通过JSON.parse转换为对象的json字符串
var clientScopeJson={"cl1":{"List":"rwe","urlList":["nclsdlc","alkdcjla"]}};
JSON.hasOwnProperty(id)返回true,但JSON.id给出undefined:
id = "cl1"
//scope = JSON.parse(clientScopeJson);
console.log(clientScopeJson);
clientId = "cl1";
exists = clientScopeJson.hasOwnProperty(clientId); // This returns as true
console.log(exists);
scopeList = clientScopeJson.clientId;
console.log(scopeList);
答案 0 :(得分:2)
如果要访问保存在变量中的密钥,可以像这样访问
const clientId = "cl1";
const scopeList = clientScopeJson[clientId];
如果您尝试使用dot,则尝试访问“clientId”键。