从API读取列表



我正试图从API读取列表。这是API返回给我的响应。

[["a",1,2,3,4,5,6,7,8,9,10,11,12], 
["b",2,3,4,5,6,7,8,9,10,11,12,13]]

Here my call

HttpResponseMessage response = await _client.GetAsync("url");
var strings = await response.Content.ReadAsStringAsync();
var stringResult = strings.Substring(1, allSymbolsString.Length-2).Split(',');
List<string> stringList = new List<string>();
List<string> cleanList = stringResult.ToList();
foreach (var s in cleanList)
{
stringList.Add(Regex.Replace(s, @"...", ""));
}
stringList.RemoveAll(s => string.IsNullOrWhiteSpace(s));
List<model> m = new List<model> { };
foreach (var s in stringList)
{
m.Add(new model
{
.
.
.
});
}
return m;

这对我来说是工作,但我想知道,有更短的方法吗?我试着读取一个流,但它给了我一个错误。我这样写。我希望我的问题能说清楚。谢谢你。

API返回的是JSON。你不能把in反序列化成字符串[][]吗?

如果你使用JSON。净:

JsonConvert.DeserializeObject<string[][]>(strings);

最新更新