cookies cookies - 1 year ago 83
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.

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download