Read JSON string as key value

前端 未结 4 2152
借酒劲吻你
借酒劲吻你 2021-02-10 14:40

I have following json:

{   
    \"serverTime\": \"2013-08-12 02:45:55,558\",
    \"data\": [
        {
            \"key1\": 1,
            \"key2\": {},
                


        
4条回答
  •  鱼传尺愫
    2021-02-10 15:20

    First create classes to parse string

    public class Key2
    {
    }
    
    public class Key3
    {
        public List key4 { get; set; }
        public string key5 { get; set; }
    }
    
    public class Key9
    {
    }
    
    public class Key10
    {
        public List key4 { get; set; }
        public string key9 { get; set; }
    }
    
    public class Datum
    {
        public int key1 { get; set; }
        public Key2 key2 { get; set; }
        public Key3 key3 { get; set; }
        public int key7 { get; set; }
        public int? key8 { get; set; }
        public Key9 key9 { get; set; }
        public Key10 key10 { get; set; }
        public int? key11 { get; set; }
    }
    
    public class RootObject
    {
        public string serverTime { get; set; }
        public List data { get; set; }
    }
    

    add reference of Newtonsoft.Json.dll

    RootObject obj = JsonConvert.DeserializeObject(jsonData);
    

    then you can access values .

提交回复
热议问题