Read JSON string as key value

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

    Try this:

    using System;
    using System.IO;
    using Newtonsoft.Json;
    
    class Program
    {
        static void Main(string[] args)
        {
            var json = File.ReadAllText("input.txt");
            var a = new { serverTime = "", data = new object[] { } };
            var c = new JsonSerializer();
            dynamic jsonObject = c.Deserialize(new StringReader(json), a.GetType());
            Console.WriteLine(jsonObject.data[0]);
        }
    }
    

提交回复
热议问题