Read JSON string as key value

前端 未结 4 2151
借酒劲吻你
借酒劲吻你 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:08

    If you're not averse to using Json.NET, you can do this:

    var jsonString = @"
    {   
        ""serverTime"": ""2013-08-12 02:45:55,558"",
        ""data"": [
            {
                ""key1"": 1,
                ""key2"": {},
                ""key3"": {
                    ""key4"": [
                        """"
                    ],
                    ""key5"": ""test2""
                },
                ""key7"": 0
            },
            {
                ""key8"": 1,
                ""key9"": {},
                ""key10"": {
                    ""key4"": [
                        """"
                    ],
                    ""key9"": ""test2""
                },
                ""key11"": 0
            }
        ] 
    }";
    
    var jsonResult = JsonConvert.DeserializeObject>(jsonString);
    var firstItem = jsonResult["data"][0];
    

    firstItem would be an array of the first item in the data array:

    Demo result

    Hope this helps.

提交回复
热议问题