Ejemplo n.º 1
0
        public static void RunExample1()
        {
            Console.WriteLine("Example 1");
            Console.WriteLine("=========");
            Console.WriteLine();

            string jsonExpression = @"
      {
        ""addressBook"": [
          {""lastName"": ""Average"", ""firstName"": ""Joe""},
          {""lastName"": ""Doe"", ""firstName"": ""Jane""},
          {""lastName"": ""Smith"", ""firstName"": ""John""}
        ]
      }";

            var        root = SLJsonNode.Parse(jsonExpression);
            SLJsonNode book = root["addressBook"];

            if (book.IsArray)
            {
                int c = book.Count;
                for (int i = 0; i < c; i++)
                {
                    SLJsonNode entry = book[i];
                    string     ln    = entry["lastName"];
                    string     fn    = entry["firstName"];
                    Console.WriteLine(fn + " " + ln);
                }
            }

            Console.WriteLine();
        }
Ejemplo n.º 2
0
        public static void RunExample2()
        {
            Console.WriteLine("Example 2");
            Console.WriteLine("=========");
            Console.WriteLine();

            string jsonExpression = RetrieveJsonExample();

            PrintNode(SLJsonNode.Parse(jsonExpression), "demo = ", 0);
            Console.WriteLine();
        }
Ejemplo n.º 3
0
        public static void RunExample4()
        {
            Console.WriteLine("Example 4");
            Console.WriteLine("=========");
            Console.WriteLine();

            string s = @"
      {
        ""options"": { ""logging"": true },

        ""sensors"": [
          { ""name"": ""Button"", ""value"": 1 },
          { ""name"": ""Temperature"", ""value"": 17.5 }
        ],

        ""actors"": [
          { ""name"": ""Lamp"", ""value"": 0 }
        ]
      }";

            /*
             * Console.WriteLine(s.Trim());
             * Console.WriteLine();
             * //*/

            var n = SLJsonNode.Parse(s);

            Console.WriteLine("n.AsJsonCompact          => " + n.AsJsonCompact);
            Console.WriteLine();

            Console.WriteLine("n[\"options\"].NodeType    => " + n["options"].NodeType);
            Console.WriteLine("n[\"options\"][\"logging\"]  => " + n["options"]["logging"]);
            Console.WriteLine("n[\"sensors\"].NodeType    => " + n["sensors"].NodeType);
            Console.WriteLine("n[\"sensors\"].Count       => " + n["sensors"].Count);
            Console.WriteLine("n[\"sensors\"][0][\"name\"]  => " + n["sensors"][0]["name"]);
            Console.WriteLine("n[\"sensors\"][1][\"value\"] => " + n["sensors"][1]["value"]);
            Console.WriteLine("n[\"missing\"][33][\"foo\"]  => " + n["missing"][33]["foo"]);
            Console.WriteLine();
        }