gpt4 book ai didi

c# - 无法在 C# 中解析此 Json 字符串

转载 作者:太空宇宙 更新时间:2023-11-03 17:25:01 25 4
gpt4 key购买 nike

我尝试使用 Newtonsoft.Json 反序列化此 json 字符串,但没有获得所需的输出。我的 json 字符串是

[
{
"id": 1,
"key": "Residential Homeowner",
"i18nText": "unknown message code DB_ENUM_UserType_residentialhomeowner",
"i18nKey": "DB_ENUM_UserType_residentialhomeowner"
},
{
"id": 8,
"key": "VAR Dealer \/ Builder",
"i18nText": "unknown message code DB_ENUM_UserType_vardealer\/builder",
"i18nKey": "DB_ENUM_UserType_vardealer\/builder"
},
{
"id": 2,
"key": "Administrator",
"i18nText": "unknown message code DB_ENUM_UserType_administrator",
"i18nKey": "DB_ENUM_UserType_administrator"
},
{
"id": 9998,
"key": "TempGuidUser",
"i18nText": "unknown message code DB_ENUM_UserType_tempguiduser",
"i18nKey": "DB_ENUM_UserType_tempguiduser"
},
{
"id": 9999,
"key": "GuidUser",
"i18nText": "unknown message code DB_ENUM_UserType_guiduser",
"i18nKey": "DB_ENUM_UserType_guiduser"
}
]

我只想要 id=1 时 key 的值。通常 json 以 {}(花括号)开头,但这里它像 [](方括号)。我见过很多例子,但没有一个对我有用。

最佳答案

Generally json starts with {} (curly bracket), but here it is like [] (square bracket).

这是因为您得到的是对象数组,而不是单个对象。数组用方括号括起来进行序列化。您应该将其反序列化为一个数组,然后在感兴趣的索引处获取对象。

关于c# - 无法在 C# 中解析此 Json 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20002432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com