将JS数组字符串转换为C#列表

时间:2019-06-24 11:59:42

标签: c# .net asp.net-core

我有一个js字符串数组"["yellow", "black"]",我正在尝试将其转换为C#列表

IV'尝试执行以下代码

stringList.Trim('[',']').ToList();

但是结果是一个列表,如果每个字符

[ "y","e","l","l","o","w"...]

关于如何做到这一点的任何想法?

THX

2 个答案:

答案 0 :(得分:1)

我们使用Newtonsoft进行所有JSON解析:

Start-Sleep -s 5 

Send-MailMessage -To $recipients -Subject $Subject -Body $body ((gsv Apache) | out-string) -From $from -SmtpServer $smtpServer -Attachments $attachment

答案 1 :(得分:1)

您可以使用新的System.Text.Json API

JsonSerializer.Parse<List<string>>("[\"yellow\", \"black\"]");

有关更多信息,您可以阅读Try the new System.Text.Json APIs