gpt4 book ai didi

c# - 使用 C# 反序列化 JSON 以返回项目

转载 作者:行者123 更新时间:2023-11-30 20:32:46 25 4
gpt4 key购买 nike

我有以下内容:

{"documents":
[{"keyPhrases":
[
"search results","Azure Search","fast search indexing","sophisticated search capabilities","Build great search experiences","time-sensitive search scenarios","service availability","managed service","service updates","index corruption","near-instantaneous responses","multiple languages","integrated Microsoft natural language stack","multiple indexes","application changes","ranking models","great relevance","years of development","primary interaction pattern","storage","Bing","data volume","rich","suggestions","hassle of dealing","Reliable throughput","website","incremental cost","complexity","faceting","traffic","mobile apps","business goals","users","applications","user expectations","Office"
],
"id":"1"}],
"errors":[]
}

我需要提取 keyPhrases 中的项目,但完全不知道该怎么做。

我尝试了以下方法:

KeyPhraseResult keyPhraseResult = new KeyPhraseResult();

/// <summary>
/// Class to hold result of Key Phrases call
/// </summary>
public class KeyPhraseResult
{
public List<string> keyPhrases { get; set; }
}

keyPhraseResult = JsonConvert.DeserializeObject<KeyPhraseResult>(content);

content 包含上面的 JSON 字符串。

但是 keyPhraseResult 返回一个空值。

任何人都可以帮助我朝着正确的方向前进吗?

谢谢。

最佳答案

public class Document
{
public List<string> keyPhrases { get; set; }
public string id { get; set; }
}

public class RootObject
{
public List<Document> documents { get; set; }
public List<object> errors { get; set; }
}

你应该有这样的结构:

var result = JsonConvert.DeserializeObject<RootObject>(content);

关于c# - 使用 C# 反序列化 JSON 以返回项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40932669/

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