Newtonsoft.Json.Linq.JArray to string array C#

90,795

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

string[] Users = model.Users.ToObject<string[]>()
Share:
90,795

Related videos on Youtube

Fighter Plane
Author by

Fighter Plane

Updated on May 17, 2021

Comments

  • Fighter Plane
    Fighter Plane almost 3 years

    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?

    • Bernd Linde
      Bernd Linde over 9 years
      Have you attempted anything? What is the definition of model.Users because it seems like it is a string[] already. The "JSON.Array" you supplied doesn't look like JSON, it looks more like an array declaration.
  • Jay
    Jay over 3 years
    if you are adding a new answer to a very old question which already has so many answers, try and add a sentence explaining why and how this is better or different.
  • Trenton McKinney
    Trenton McKinney over 3 years
    The provided answer was flagged for review as a Low Quality Post. Here are some guidelines for How do I write a good answer?. This provided answer could benefit from an explanation. Code only answers are not considered "good" answers. From Review.