How to return a list from a json? [duplicate]

-2

Here is the result:

  

{"response":{"numFound":2654,"start":0,"docs":[{"id":"l3ade68b8g5db3b0b3","langID":1,"url":"/ministerio-codigo-de-honra/quao-grande.html","title":"Quão grande","band":"Ministério Código de Honra"},{"id":"l3ade68b8geb421fa3","langID":1,"url":"/mattos-nascimento/quao-grande.html","title":"Quão Grande","band":"Mattos Nascimento"},{"id":"l3ade68b8g7acefea3","langID":1,"url":"/andre-valadao/quao-grande-es-tu.html","title":"Quão Grande És Tu","band":"André Valadão"},{"id":"l3ade68b7g0109aea3","langID":1,"url":"/hinario-adventista/quao-grande-es-tu.html","title":"Quão Grande és Tu","band":"Hinário Adventista"},{"id":"l3ade68b8g2d4bfea3","langID":1,"url":"/padre-marcelo-rossi/quao-grande-es-tu.html","title":"Quão Grande Es Tu","band":"Padre Marcelo Rossi"}]},"highlighting":{"l3ade68b8g5db3b0b3":{},"l3ade68b8geb421fa3":{},"l3ade68b8g7acefea3":{},"l3ade68b7g0109aea3":{},"l3ade68b8g2d4bfea3":{}}}

How can I generate a list or array with the above result?

    
asked by anonymous 25.11.2017 / 00:19

1 answer

1

Following the same logic as the question How to get value from a json? the Json that returns in classes, example :

public class Rootobject
{
    public Response response { get; set; }
    public Highlighting highlighting { get; set; }
}

public class Response
{
    public int numFound { get; set; }
    public int start { get; set; }
    public Doc[] docs { get; set; }
}

public class Doc
{
    public string id { get; set; }
    public int langID { get; set; }
    public string url { get; set; }
    public string title { get; set; }
    public string band { get; set; }
}

public class Highlighting
{
    public L3ade68b8g5db3b0b3 l3ade68b8g5db3b0b3 { get; set; }
    public L3ade68b8geb421fa3 l3ade68b8geb421fa3 { get; set; }
    public L3ade68b8g7acefea3 l3ade68b8g7acefea3 { get; set; }
    public L3ade68b7g0109aea3 l3ade68b7g0109aea3 { get; set; }
    public L3ade68b8g2d4bfea3 l3ade68b8g2d4bfea3 { get; set; }
}

public class L3ade68b8g5db3b0b3
{
}

public class L3ade68b8geb421fa3
{
}

public class L3ade68b8g7acefea3
{
}

public class L3ade68b7g0109aea3
{
}

public class L3ade68b8g2d4bfea3
{
}

Note that some classes are open, that is, without features of their properties, but by Json is what can be used.

For invalid characters use Encoding like this:

using (WebClient wc = new WebClient())
{
     wc.Encoding = System.Text.Encoding.UTF8;
}

Using the Newtonsoft.Json package, do:

Rootobject result = Newtonsoft.Json.JsonConvert.DeserializeObject<Rootobject>(json);
    
25.11.2017 / 00:21