Exemplo n.º 1
0
        static void Main115(string[] args)
        {
            var json = @"
[
	{""B"":{""I"":1111,""M"":""你好"",""O"":""Operation"",""S"":1000},""H"":{""T"":null,""RT"":null,""SEQ"":null,""RSEQ"":null,""I"":null,""L"":null,""RR"":null,""S"":null,""R"":[{""A"":""app1"",""G"":""group1"",""U"":""user1""}],""RO"":null,""ST"":null,""ET"":""2015-01-26 17:19:30.3560275+08:00"",""SC"":null,""RV"":null}}
	,
	{""B1"":{""I"":1111,""M"":""你好"",""O"":""Operation"",""S"":1000},""H"":{""T"":null,""RT"":null,""SEQ"":null,""RSEQ"":null,""I"":null,""L"":null,""RR"":null,""S"":null,""R"":[{""A"":""app1"",""G"":""group1"",""U"":""user1""},{""A"":""app1"",""G"":""group1"",""U"":""user1""}],""RO"":null,""ST"":null,""ET"":""2015-01-26 17:19:30.3560275+08:00"",""SC"":null,""RV"":null}}
]";

            json = @"{F2: [{a:""asdsad""}],F1: ""F1f1f1f1f1"",""B"":{""I"":999,""M"":""你好"",""O"":""Operation"",""S"":1000},""H"":{""T"":null,""RT"":1111111,""SEQ"":null,""RSEQ"":null,""RR"":null,""S"":null,""R"":[{""A"":""app1"",""G"":""group1"",""U"":""user1""}],""RO"":null,""ST"":null,""ET"":""2015-01-26 17:19:30.3560275+08:00"",""SC"":null,""RV"":null}}";
            json = @"
{
	F1 : ""F1.Value"" ,
	F2 :
            {
                F2 : ""F2.F2.Value""
            } ,
	F3 :
            [
                {
                    F1 : ""F3[0].F1.Value"" ,
                    F2 : ""F3[0].F2.Value""
                } ,
                {
                    F4 : ""F3[0].F4.Value"" ,
                    F5 : ""F3[1].F5.Value""
                }
            ] ,
    F4 :
            [
                ""1"" ,
                ""2""
            ]
}
";

            var          jToken = JToken.Parse(json);
            KeyValueNode node   = KeyValueNode.CreateFromJToken(jToken, null);

            Console.WriteLine(node["F1"]);
            Console.WriteLine(node["F2"]["F2"].Value);
            Console.WriteLine(node["F3"][0]["F1"].Value);
            Console.WriteLine(node["F3"][1]["F5"]);
            Console.WriteLine(node["F4"][1].Value);

            node["F1"].Value          += " new";
            node["F2"]["F2"].Value    += " new";
            node["F3"][0]["F1"].Value += " new";
            node["F3"][1]["F5"].Value += " new";
            node["F4"][1].Value       += " new";

            Console.WriteLine(node["F1"]);
            Console.WriteLine(node["F2"]["F2"].Value);
            Console.WriteLine(node["F3"][0]["F1"].Value);
            Console.WriteLine(node["F3"][1]["F5"]);
            Console.WriteLine(node["F4"][1].Value);

            Console.WriteLine("==========================");
            json = node.ToJson(false);
            Console.WriteLine(json);
            json = node.ToJson();
            Console.WriteLine(json);
            //json = JsonConvert.SerializeObject(node);

            var jObject = new JObject();

            jObject.Add("Entered", DateTime.Now);
            dynamic album = jObject;

            album.AlbumName    = "Dirty Deeds Done Dirt Cheap";
            album.Artist       = "AC/DC";
            album.YearReleased = 1976;
            album.Songs        = new JArray() as dynamic;
            dynamic song = new JObject();

            song.SongName   = "Dirty Deeds Done Dirt Cheap";
            song.SongLength = "4:11";
            album.Songs.Add(song);
            song            = new JObject();
            song.SongName   = "Love at First Feel";
            song.SongLength = "3:10";
            album.Songs.Add(song);
            node = KeyValueNode
                   .CreateFromJToken
                   (
                (JToken)album
                , null
                   );
            Console.WriteLine
            (
                node["Songs"][0]["SongName"].Value
            );

            Console.WriteLine("==========================");

            node["Songs"][0]["SongName"].Value += " new";
            json = node.ToJson(false);
            Console.WriteLine(json);
            json = node.ToJson();
            Console.WriteLine(json);


            Console.ReadLine();
        }