1

I have a js stringify array "["yellow", "black"]" and I'm trying to convert it to C# list

Iv' tried to do the following code

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

But the result is a list if every char

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

Any ideas of how can I do that?

THX

4

2 Answers 2

1

You can use the new System.Text.Json APIs

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

For further information you can read Try the new System.Text.Json APIs.

Sign up to request clarification or add additional context in comments.

Comments

1

We use Newtonsoft for all JSON parsing:

string[] arr = Newtonsoft.Json.JsonConvert.DeserializeObject<string[]>("[\"yellow\", \"black\"]");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.