cookies cookies - 5 months ago 23
C# Question

How do I convert JSON to Array

If I have the JSON string:


How do I store this in an array so that in C# it will be this?

string[] synonyms = {"house","abode","appartment","condo","dwelling"};

I am trying to use the Newtonsoft.Json library.


Create a RootObject class.

public class RootObject
    public List<string> synonyms { get; set; }

Create a RootObject by using this:

RootObject obj = JsonConvert.DeserializeObject<RootObject>(json);

// Acessing synonyms property of obj
List<string> syn = obj.synonyms; // call to Array if you want