【发布时间】:2022-01-03 21:43:00
【问题描述】:
我有这段代码,它从this api 下载一个字符串,然后反序列化它。 我已经想出了如何访问“单词”和“语音”对象,但是我将如何访问“语音”数组中的“音频”对象,或者“含义”中的一些对象? 1
private void Button1_Click(object sender, EventArgs e)
{
string result = "";
string link = ($"https://api.dictionaryapi.dev/api/v2/entries/en/hello");
var json = new WebClient().DownloadString(link);
var jsonDes = JsonConvert.DeserializeObject<List<DictionaryAPIResultData>>(json);
foreach (var data in jsonDes)
{
Console.WriteLine( data.phonetics);
}
}
public class DictionaryAPIResultData
{
[JsonProperty("word")]
internal string word { get; set; }
[JsonProperty("phonetics")]
internal List<string> phonetics { get; set; }
}
希望有人能提供帮助!
【问题讨论】:
-
我建议你使用像 NAUDIO 这样的 n mp3 流媒体,我不认为 c# 声音播放器读取 mp3,只有 wav
-
顺便说一句,如果你有 JSON 并且你不知道如何围绕它设计你的容器类,那么有一些有用的工具可以为你做这件事。例如:json2csharp.com