从 Newtonsoft. Json. Linq.JArray 到 string array C #

我有一个 JSON 数组,比如

model.Users =  ["Joe","Barny","Power","Tester"]

模型是 dynamic

我想把 model.Users转换成 string[] Users

string[] Users = model.Users

我该怎么做?

96809 次浏览

If model.Users is of type Newtonsoft.Json.Linq.JArray try to call:

string[] Users = model.Users.ToObject<string[]>()
string[] Users = new string[20];


int i = 0;


foreach ( string item in model.Users )
{
Users[i] = item;
i++;
}