some ideas how to read this simple JSON String to a List?
["amazon.de","ebay.de","fischevortische.de","homefuerst.de"]
i just wanna add every item to my List blackList
some ideas how to read this simple JSON String to a List?
["amazon.de","ebay.de","fischevortische.de","homefuerst.de"]
i just wanna add every item to my List blackList
You have two solutions:
Quick but only for a list of string.
string jsonText = "[\"amazon.de\",\"ebay.de\",\"fischevortische.de\",\"homefuerst.de\"]";
char[] separators = new char[] {'[', ']', ',', '"'};
string[] result1 = jsonText.Split(separators, StringSplitOptions.RemoveEmptyEntries);
Using JSON library (included in .NET)
string jsonText = "[\"amazon.de\",\"ebay.de\",\"fischevortische.de\",\"homefuerst.de\"]";
var jss = new JavaScriptSerializer();
var result2 = jss.Deserialize<string[]>(jsonText);
string json = "[\"amazon.de\",\"ebay.de\",\"fischevortische.de\",\"homefuerst.de\"]";
List<string> parsed = Newtonsoft.Json.JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JArray>(json).Values<string>().ToList();
var result = JsonConvert.DeserializeObject<List<string>>();