我有一个物体。在我的对象中,有一个带正斜杠的钥匙,我想访问带正斜杠pattern
我尝试了几种无效的方法,请提供访问pattern
属性的解决方案。对象在底部
test.attributes./worker/workAssignment/homeOrganizationalUnits/typeCode/codeValue
SyntaxError: Unexpected token /
key = '/worker/workAssignment/homeOrganizationalUnits/typeCode/codeValue'
test.attributes.key
undefined
test.attributes.["key"]
Thrown:
SyntaxError: Unexpected token [
test.attributes.\/worker\/workAssignment\/homeOrganizationalUnits\/typeCode\/codeValue
Thrown:
SyntaxError: Invalid or unexpected token
{
"attributes": {
"/worker/workAssignment/homeOrganizationalUnits/typeCode/codeValue": {
"pattern": "Department"
}
},
"value": {
"links": [{
"href": "/codelists/hr/v3/worker-management/departments/WFN/1?$filter=foreignKey eq {payrollGroupCode}",
"mediaType": "application/json",
"method": "GET"
}]
}
}
答案 0 :(得分:1)
host.RunAsCustomService();
或var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
var pathToContentRoot = Path.GetDirectoryName(pathToExe);
Directory.SetCurrentDirectory(pathToContentRoot);
CreateWebHostBuilder(args)
.Build()
.RunAsService();
都很好。
答案 1 :(得分:1)
您可以在键名中使用'/'
字符进行对象访问,只要它是用于查找的变量的值即可。
var key = '///';
var obj = { '///': 'foo' };
obj[key];
> 'foo'
有关更多信息,请查看Property Accessors
上的MDN文档