c# - Google Cloud Platform - Secret Manager 未格式化为 JSONObject 并给出错误
问题描述
我正在使用 Google Cloud Platform 开发 C# asp.net Web 应用程序。我正在使用存储 Google ClientSecret 和 ClientId 的 Secret Manager 功能。然后,我使用下面的代码,因为我的讲师使用它,我确信它可以工作,使用我的谷歌云项目名称、我的 secretId 和版本作为参数,使用密钥管理器功能获取客户端密钥和 ID。
public string GetGoogleClientId(string projectId, string SecretId, string version)
{
SecretManagerServiceClient client = SecretManagerServiceClient.Create();
SecretVersionName secretVersionName = new SecretVersionName(projectId, SecretId, version);
AccessSecretVersionResponse result = client.AccessSecretVersion(secretVersionName);
string payload = result.Payload.Data.ToStringUtf8().ToString();
dynamic keys = JsonConvert.DeserializeObject(payload); //Gives the error here
JObject jObject = JObject.Parse(payload);
JToken jKey = jObject["Authentication:Google:ClientId"];
return jKey.ToString();
}
但是,我收到以下错误:
'解析值时遇到意外字符:。路径'',第 0 行,位置 0。'
变量有效负载中生成的字符串返回我试图序列化的以下字符串:
{
"Authentication:Google:ClientSecret": "Hidden for security reasons",
"Authentication:Google:ClientId": "Hidden for security reasons"
}
请问我做错了什么?
解决方案
推荐阅读
- c++ - 尝试使用 Ifstream 打开 .txt 文件的 C++ 问题
- javascript - Mocha/Chai TypeError:无法读取未定义的属性“包含”
- android - 手机抖动随机颜色生成器
- postgresql - 如何使用现有值更新postgres sql中的字符串连接
- git - 如果我从本地未提交的工作创建补丁 - 它会失败。如果我提交我的工作,然后创建补丁,它会应用而不会失败。为什么?
- java - 如何从代码中知道两个类之间的关系是聚合还是组合?
- swift - 图像识别Swift时不同位置的SCNNode位置
- powershell - PowerShell:捕获错误但不循环继续?
- ruby-on-rails - Rails - 关闭当前的数据库连接
- python - 当我从批处理文件和任务计划程序运行脚本时,子进程运行、check_output、Popen 返回空字符串