【发布时间】:2020-04-30 22:25:31
【问题描述】:
我正在尝试将 JObject 中的数组读入字符串 [],但我不知道如何操作。
代码非常简单,如下所示,但不起作用。失败并出现错误无法将 JToken 转换为 string[]
JObject Items = jsonSerializer.Deserialize<JObject>(jtr);
string[] brands = null;
brands = (string[])Items.SelectToken("Documents[0].Brands");
当我想读取一个简单的布尔值时,以下方法有效,所以我知道我在正确的地方。
IsAdmin = (bool)Items.SelectToken("Documents[0].IsAdmin");
Documents[0] 中的 JObject 如下所示
{
"id": "961AA6A6-F372-ZZZZ-1270-ZZZZZ",
"ApiKey": "SDKTest",
"ConsumerName": "SDKTest",
"IsAdmin": false,
"Brands": [
"ZZZ"
],
"IsSdkUser": true
}
如何将 Brands 数组读入我的 string[] 品牌?
【问题讨论】: