-7

我想使用 JSON 结果。但我不明白这个案子。

{
    "result": {
        "employers": [
            {
                "nome": "Maria",
                "id": 2,
                "setor": "Setor1"
            },
            {
                "nome": "Abreu",
                "id": 4,
                "setor": "Setor2"
            }
        ]
    }
}

private void button1_Click(object sender, EventArgs e)
{
    Employers ll = JsonConvert.DeserializeObject<Employers>(jsonString);
    Console.WriteLine(ll);
}
4

1 回答 1

2
class Employer
{
    [JsonProperty("nome")]
    public string Nome { get; set; }

    [JsonProperty("id")]
    public string Id { get; set; }

    [JsonProperty("setor")]
    public string Setor { get; set; }
}

class Employers : List<Employer>
{
}

Employers employers = JObject.Parse(json)["result"]["employers"].ToObject<Employers>();
于 2013-10-08T09:17:18.973 回答