如何使带有数组列表的字符串可迭代

我有一个像下面这样的值

[['20190717','7347.00','7291.00','6929.00','7498.00','131','212761','1563195158.00'],['20190716','7291.00','7584.00','7205.00','7800.00','205','786281','5732513136.00'],['20190715','7584.00','7561.00','7262.00','7911.00','201','957135','7258611941.00'],['20190714','7561.00','7796.00','7407.00','7909.00','411','1715426','12970206490.00'],['20190713','7796.00','7428.00','7602.00','7799.00','468','2622089','20442582710.00'],['20190710','7428.00','7140.00','7070.00','7497.00','250','947330','7037099454.00'],['20190709','7140.00','7442.00','7070.00','7449.00','219','665235','4749481884.00'],['20190708','7442.00','7164.00','7300.00','7522.00','276','1171931','8721432059.00'],['20190707','7164.00','6882.00','6540.00','7226.00','324','1125954','8066782953.00']]

所以我想在语句中使用上述数据foreach并访问数组项的每个值,例如item[0]. 我尝试了这样的操作,但这不是我想要的,并且我无法通过索引获取值

var splited = value.Replace("[[", "[").Replace("]]", "]").Split(new string[] { "],"}, StringSplitOptions.RemoveEmptyEntries);


函数式编程
浏览 76回答 1
1回答

江户川乱折腾

建议在使用之前对其进行“反序列化”。由于您的示例看起来像 json,因此您可以添加对 nuget 包NewtonSoft.Json的引用并像这样反序列化:string json = "[['20190717','7347.00','7291.00','6929.00','7498.00','131','212761','1563195158.00'],['20190716','7291.00','7584.00','7205.00','7800.00','205','786281','5732513136.00'],['20190715','7584.00','7561.00','7262.00','7911.00','201','957135','7258611941.00'],['20190714','7561.00','7796.00','7407.00','7909.00','411','1715426','12970206490.00'],['20190713','7796.00','7428.00','7602.00','7799.00','468','2622089','20442582710.00'],['20190710','7428.00','7140.00','7070.00','7497.00','250','947330','7037099454.00'],['20190709','7140.00','7442.00','7070.00','7449.00','219','665235','4749481884.00'],['20190708','7442.00','7164.00','7300.00','7522.00','276','1171931','8721432059.00'],['20190707','7164.00','6882.00','6540.00','7226.00','324','1125954','8066782953.00']]";List<List<string>> deserializedList = JsonConvert.DeserializeObject<List<List<string>>>(json);foreach (List<string> innerList in deserializedList){    foreach (string item in innerList)    {        Console.WriteLine(item);    }}
打开App,查看更多内容
随时随地看视频慕课网APP