-4

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

1
  • Please read our Ask a question Commented May 29, 2015 at 7:10

3 Answers 3

1

You have two solutions:

  1. 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);
    
  2. 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);
    
Sign up to request clarification or add additional context in comments.

Comments

0
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();

Comments

0
var result = JsonConvert.DeserializeObject<List<string>>();

1 Comment

please describe more..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.