Read JSON string as key value

前端 未结 4 1271
别那么骄傲
别那么骄傲 2021-02-10 14:29

I have following json:

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


        
4条回答
  •  清酒与你
    2021-02-10 15:26

    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.

提交回复
热议问题