Newtonsoft.Json.Linq.JArray to string array C#
C#ArraysJsonStringjson.netC# Problem Overview
I have a JSON Array like
model.Users = ["Joe","Barny","Power","Tester"]
the model is dynamic
I want to convert model.Users
to string[] Users
string[] Users = model.Users
How can I do that?
C# Solutions
Solution 1 - C#
If model.Users
is of type Newtonsoft.Json.Linq.JArray
try to call:
string[] Users = model.Users.ToObject<string[]>()
Solution 2 - C#
string[] Users = new string[20];
int i = 0;
foreach ( string item in model.Users )
{
Users[i] = item;
i++;
}