从 API 中读取列表

Read a list from an API

我正在尝试从 API 中读取列表。 这是 API returns 给我的回复。

[["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]]

这是我的电话

            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。 你不能反序列化成 string[][] 吗?

如果您正在使用 JSON.NET:

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