WeixiangYan/CodeTransOcean huggingface dataset:
Task: Zig-zag matrix








VB: ZigZag(Cint(WScript.Arguments(0)))

Function ZigZag(n)
	Dim arrZ()
	ReDim arrZ(n-1,n-1)
	i = 1
	j = 1
	For e = 0 To (n^2) - 1
		arrZ(i-1,j-1) = e
		If ((i + j ) And 1) = 0 Then
			If j < n Then
				j = j + 1
			Else
				i = i + 2
			End If
			If i > 1 Then
				i = i - 1
			End If
		Else
			If i < n Then
				i = i + 1
			Else
				j = j + 2
			End If
			If j > 1 Then
				j = j - 1
			End If
		End If
	Next
	For k = 0 To n-1
		For l = 0 To n-1
			WScript.StdOut.Write Right("  " & arrZ(k,l),3)
		Next
		WScript.StdOut.WriteLine
	Next
End Function



Fortran: PROGRAM ZIGZAG
 
  IMPLICIT NONE
    INTEGER, PARAMETER :: size = 5
    INTEGER :: zzarray(size,size), x(size*size), y(size*size), i, j
     
    
    x = (/ ((j, i = 1, size), j = 1, size) /)
    y = (/ ((i, i = 1, size), j = 1, size) /)
   
    
    DO i = 2, size*size
       j = i - 1
       DO WHILE (j>=1 .AND. (x(j)+y(j)) > (x(i)+y(i)))
          j = j - 1
       END DO
       x(j+1:i) = cshift(x(j+1:i),-1)
       y(j+1:i) = cshift(y(j+1:i),-1)
    END DO
 
    
    DO i = 1, size*size
       IF (MOD(x(i)+y(i), 2) == 0) THEN
          zzarray(x(i),y(i)) = i - 1
       ELSE
          zzarray(y(i),x(i)) = i - 1
       END IF
    END DO
  
    
    DO j = 1, size
       DO i = 1, size
          WRITE(*, "(I5)", ADVANCE="NO") zzarray(i,j)
       END DO
       WRITE(*,*)
    END DO
  
 END PROGRAM ZIGZAG
Task: Zig-zag matrix






PHP: function ZigZagMatrix($num) {
    $matrix = array();
    for ($i = 0; $i < $num; $i++){
		$matrix[$i] = array();
	}
	
    $i=1;
	$j=1;
    for ($e = 0; $e < $num*$num; $e++) {
        $matrix[$i-1][$j-1] = $e;
        if (($i + $j) % 2 == 0) {
            if ($j < $num){
				$j++;
			}else{
				$i += 2;
			}
            if ($i > 1){ 
				$i --;
			}
        } else {
            if ($i < $num){ 
				$i++;
			}else{
				$j += 2;
			}
            if ($j > 1){
				$j --;
			}
        }
    }
	return $matrix;
}





Fortran: PROGRAM ZIGZAG
 
  IMPLICIT NONE
    INTEGER, PARAMETER :: size = 5
    INTEGER :: zzarray(size,size), x(size*size), y(size*size), i, j
     
    
    x = (/ ((j, i = 1, size), j = 1, size) /)
    y = (/ ((i, i = 1, size), j = 1, size) /)
   
    
    DO i = 2, size*size
       j = i - 1
       DO WHILE (j>=1 .AND. (x(j)+y(j)) > (x(i)+y(i)))
          j = j - 1
       END DO
       x(j+1:i) = cshift(x(j+1:i),-1)
       y(j+1:i) = cshift(y(j+1:i),-1)
    END DO
 
    
    DO i = 1, size*size
       IF (MOD(x(i)+y(i), 2) == 0) THEN
          zzarray(x(i),y(i)) = i - 1
       ELSE
          zzarray(y(i),x(i)) = i - 1
       END IF
    END DO
  
    
    DO j = 1, size
       DO i = 1, size
          WRITE(*, "(I5)", ADVANCE="NO") zzarray(i,j)
       END DO
       WRITE(*,*)
    END DO
  
 END PROGRAM ZIGZAG
Task: Zig-zag matrix






PHP: function ZigZagMatrix($num) {
    $matrix = array();
    for ($i = 0; $i < $num; $i++){
		$matrix[$i] = array();
	}
	
    $i=1;
	$j=1;
    for ($e = 0; $e < $num*$num; $e++) {
        $matrix[$i-1][$j-1] = $e;
        if (($i + $j) % 2 == 0) {
            if ($j < $num){
				$j++;
			}else{
				$i += 2;
			}
            if ($i > 1){ 
				$i --;
			}
        } else {
            if ($i < $num){ 
				$i++;
			}else{
				$j += 2;
			}
            if ($j > 1){
				$j --;
			}
        }
    }
	return $matrix;
}
Task: Zig-zag matrix






PHP: function ZigZagMatrix($num) {
    $matrix = array();
    for ($i = 0; $i < $num; $i++){
		$matrix[$i] = array();
	}
	
    $i=1;
	$j=1;
    for ($e = 0; $e < $num*$num; $e++) {
        $matrix[$i-1][$j-1] = $e;
        if (($i + $j) % 2 == 0) {
            if ($j < $num){
				$j++;
			}else{
				$i += 2;
			}
            if ($i > 1){ 
				$i --;
			}
        } else {
            if ($i < $num){ 
				$i++;
			}else{
				$j += 2;
			}
            if ($j > 1){
				$j --;
			}
        }
    }
	return $matrix;
}






Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Test_Zig_Zag is

   type Matrix is array (Positive range <>, Positive range <>) of Natural;
   function Zig_Zag (Size : Positive) return Matrix is
      Data : Matrix (1..Size, 1..Size);
      I, J : Integer := 1;
   begin
      Data (1, 1) := 0;
      for Element in 1..Size**2 - 1 loop
         if (I + J) mod 2 = 0 then
            
            if J < Size then
               J := J + 1;
            else
               I := I + 2;
            end if;
            if I > 1 then
               I := I - 1;
            end if;
         else
            
            if I < Size then
               I := I + 1;
            else
               J := J + 2;
            end if;
            if J > 1 then
               J := J - 1;
            end if;
         end if;
         Data (I, J) := Element;
      end loop;
      return Data;
   end Zig_Zag;
   
   procedure Put (Data : Matrix) is
   begin
      for I in Data'Range (1) loop
         for J in Data'Range (2) loop
            Put (Integer'Image (Data (I, J)));
         end loop;
         New_Line;
      end loop;
   end Put;

begin
   Put (Zig_Zag (5));
end Test_Zig_Zag;
Task: Add a variable to a class instance at runtime



C#: 







using System;
using System.Dynamic;

namespace DynamicClassVariable
{
    internal static class Program
    {
        #region Static Members

        private static void Main()
        {
            
            
            dynamic sampleObj = new ExpandoObject();
            
            sampleObj.bar = 1;
            Console.WriteLine( "sampleObj.bar = {0}", sampleObj.bar );

            
            
            
            
            Console.WriteLine( "< Press any key >" );
            Console.ReadKey();
        }

        #endregion
    }
}









Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Dynamic is
   package Abstract_Class is
      type Class is limited interface;
      function Boo (X : Class) return String is abstract;
   end Abstract_Class;
   use Abstract_Class;

   package Base_Class is
      type Base is new Class with null record;
      overriding function Boo (X : Base) return String;
   end Base_Class;
   
   package body Base_Class is
      function Boo (X : Base) return String is
      begin
         return "I am Class";
      end Boo;
   end Base_Class;
   use Base_Class;

   E : aliased Base;  
   
begin
   
   declare
      type Monkey_Patch (Root : access Base) is new Class with record
         Foo : Integer := 1;
      end record;
      overriding function Boo (X : Monkey_Patch) return String;
      function Boo (X : Monkey_Patch) return String is
      begin 
         return X.Root.Boo;
      end Boo;
      EE : Monkey_Patch (E'Access); 
   begin
      Put_Line (EE.Boo & " with" & Integer'Image (EE.Foo));
   end;
end Dynamic;
Task: Add a variable to a class instance at runtime




Go: package main

import (
    "bufio"
    "fmt"
    "log"
    "os"
)

type SomeStruct struct {
    runtimeFields map[string]string
}

func check(err error) {
    if err != nil {
        log.Fatal(err)
    }
}

func main() {
    ss := SomeStruct{make(map[string]string)}
    scanner := bufio.NewScanner(os.Stdin)
    fmt.Println("Create two fields at runtime: ")
    for i := 1; i <= 2; i++ {
        fmt.Printf("  Field #%d:\n", i)
        fmt.Print("       Enter name  : ")
        scanner.Scan()
        name := scanner.Text()
        fmt.Print("       Enter value : ")
        scanner.Scan()
        value := scanner.Text()
        check(scanner.Err())
        ss.runtimeFields[name] = value
        fmt.Println()
    }
    for {
        fmt.Print("Which field do you want to inspect ? ")
        scanner.Scan()
        name := scanner.Text()
        check(scanner.Err())
        value, ok := ss.runtimeFields[name]
        if !ok {
            fmt.Println("There is no field of that name, try again")
        } else {
            fmt.Printf("Its value is '%s'\n", value)
            return
        }
    }
}








Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Dynamic is
   package Abstract_Class is
      type Class is limited interface;
      function Boo (X : Class) return String is abstract;
   end Abstract_Class;
   use Abstract_Class;

   package Base_Class is
      type Base is new Class with null record;
      overriding function Boo (X : Base) return String;
   end Base_Class;
   
   package body Base_Class is
      function Boo (X : Base) return String is
      begin
         return "I am Class";
      end Boo;
   end Base_Class;
   use Base_Class;

   E : aliased Base;  
   
begin
   
   declare
      type Monkey_Patch (Root : access Base) is new Class with record
         Foo : Integer := 1;
      end record;
      overriding function Boo (X : Monkey_Patch) return String;
      function Boo (X : Monkey_Patch) return String is
      begin 
         return X.Root.Boo;
      end Boo;
      EE : Monkey_Patch (E'Access); 
   begin
      Put_Line (EE.Boo & " with" & Integer'Image (EE.Foo));
   end;
end Dynamic;
Task: Add a variable to a class instance at runtime







Python: class empty(object):
    pass
e = empty()





Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Dynamic is
   package Abstract_Class is
      type Class is limited interface;
      function Boo (X : Class) return String is abstract;
   end Abstract_Class;
   use Abstract_Class;

   package Base_Class is
      type Base is new Class with null record;
      overriding function Boo (X : Base) return String;
   end Base_Class;
   
   package body Base_Class is
      function Boo (X : Base) return String is
      begin
         return "I am Class";
      end Boo;
   end Base_Class;
   use Base_Class;

   E : aliased Base;  
   
begin
   
   declare
      type Monkey_Patch (Root : access Base) is new Class with record
         Foo : Integer := 1;
      end record;
      overriding function Boo (X : Monkey_Patch) return String;
      function Boo (X : Monkey_Patch) return String is
      begin 
         return X.Root.Boo;
      end Boo;
      EE : Monkey_Patch (E'Access); 
   begin
      Put_Line (EE.Boo & " with" & Integer'Image (EE.Foo));
   end;
end Dynamic;
Task: Add a variable to a class instance at runtime



C#: 







using System;
using System.Dynamic;

namespace DynamicClassVariable
{
    internal static class Program
    {
        #region Static Members

        private static void Main()
        {
            
            
            dynamic sampleObj = new ExpandoObject();
            
            sampleObj.bar = 1;
            Console.WriteLine( "sampleObj.bar = {0}", sampleObj.bar );

            
            
            
            
            Console.WriteLine( "< Press any key >" );
            Console.ReadKey();
        }

        #endregion
    }
}
Task: Add a variable to a class instance at runtime







Python: class empty(object):
    pass
e = empty()
Task: Add a variable to a class instance at runtime




Go: package main

import (
    "bufio"
    "fmt"
    "log"
    "os"
)

type SomeStruct struct {
    runtimeFields map[string]string
}

func check(err error) {
    if err != nil {
        log.Fatal(err)
    }
}

func main() {
    ss := SomeStruct{make(map[string]string)}
    scanner := bufio.NewScanner(os.Stdin)
    fmt.Println("Create two fields at runtime: ")
    for i := 1; i <= 2; i++ {
        fmt.Printf("  Field #%d:\n", i)
        fmt.Print("       Enter name  : ")
        scanner.Scan()
        name := scanner.Text()
        fmt.Print("       Enter value : ")
        scanner.Scan()
        value := scanner.Text()
        check(scanner.Err())
        ss.runtimeFields[name] = value
        fmt.Println()
    }
    for {
        fmt.Print("Which field do you want to inspect ? ")
        scanner.Scan()
        name := scanner.Text()
        check(scanner.Err())
        value, ok := ss.runtimeFields[name]
        if !ok {
            fmt.Println("There is no field of that name, try again")
        } else {
            fmt.Printf("Its value is '%s'\n", value)
            return
        }
    }
}
Task: Add a variable to a class instance at runtime






PHP: class E {};

$e=new E();

$e->foo=1;

$e->{"foo"} = 1; // using a runtime name
$x = "foo";
$e->$x = 1; // using a runtime name in a variable






Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Dynamic is
   package Abstract_Class is
      type Class is limited interface;
      function Boo (X : Class) return String is abstract;
   end Abstract_Class;
   use Abstract_Class;

   package Base_Class is
      type Base is new Class with null record;
      overriding function Boo (X : Base) return String;
   end Base_Class;
   
   package body Base_Class is
      function Boo (X : Base) return String is
      begin
         return "I am Class";
      end Boo;
   end Base_Class;
   use Base_Class;

   E : aliased Base;  
   
begin
   
   declare
      type Monkey_Patch (Root : access Base) is new Class with record
         Foo : Integer := 1;
      end record;
      overriding function Boo (X : Monkey_Patch) return String;
      function Boo (X : Monkey_Patch) return String is
      begin 
         return X.Root.Boo;
      end Boo;
      EE : Monkey_Patch (E'Access); 
   begin
      Put_Line (EE.Boo & " with" & Integer'Image (EE.Foo));
   end;
end Dynamic;
Task: Add a variable to a class instance at runtime






PHP: class E {};

$e=new E();

$e->foo=1;

$e->{"foo"} = 1; // using a runtime name
$x = "foo";
$e->$x = 1; // using a runtime name in a variable
Task: JSON



C#: using System;
using System.Collections.Generic;
using System.Web.Script.Serialization;

class Program
{
    static void Main()
    {
        var people = new Dictionary<string, object> {{"1", "John"}, {"2", "Susan"}};
        var serializer = new JavaScriptSerializer();
        
        var json = serializer.Serialize(people);
        Console.WriteLine(json);

        var deserialized = serializer.Deserialize<Dictionary<string, object>>(json);
        Console.WriteLine(deserialized["2"]);

        var jsonObject = serializer.DeserializeObject(@"{ ""foo"": 1, ""bar"": [10, ""apples""] }");
        var data = jsonObject as Dictionary<string, object>;
        var array = data["bar"] as object[];
        Console.WriteLine(array[1]);
    }
}









Ada: with Ada.Text_IO;
with GNATCOLL.JSON;
 
procedure JSON_Test is
   use Ada.Text_IO;
   use GNATCOLL.JSON;
 
   JSON_String : constant String := "{""name"":""Pingu"",""born"":1986}";
   
   Penguin : JSON_Value := Create_Object;
   Parents : JSON_Array;
begin
   Penguin.Set_Field (Field_Name => "name", 
                      Field      => "Linux");
   
   Penguin.Set_Field (Field_Name => "born",
                      Field      => 1992);
   
   Append (Parents, Create ("Linus Torvalds"));
   Append (Parents, Create ("Alan Cox"));
   Append (Parents, Create ("Greg Kroah-Hartman"));
 
   Penguin.Set_Field (Field_Name => "parents",
                      Field      => Parents);
   
   Put_Line (Penguin.Write);

   Penguin := Read (JSON_String, "json.errors");
   
   Penguin.Set_Field (Field_Name => "born",
                      Field      => 1986);
   
   Parents := Empty_Array;
   Append (Parents, Create ("Otmar Gutmann"));
   Append (Parents, Create ("Silvio Mazzola"));  
   
   Penguin.Set_Field (Field_Name => "parents",
                      Field      => Parents);
   
   Put_Line (Penguin.Write);
end JSON_Test;
Task: JSON


C++: #include "Core/Core.h"

using namespace Upp;

CONSOLE_APP_MAIN
{
	JsonArray a;
	a << Json("name", "John")("phone", "1234567") << Json("name", "Susan")("phone", "654321");
	String txt = ~a;
	Cout() << txt << '\n';
	Value v = ParseJSON(txt);
	for(int i = 0; i < v.GetCount(); i++)
		Cout() << v[i]["name"] << ' ' << v[i]["phone"] << '\n';
}










Ada: with Ada.Text_IO;
with GNATCOLL.JSON;
 
procedure JSON_Test is
   use Ada.Text_IO;
   use GNATCOLL.JSON;
 
   JSON_String : constant String := "{""name"":""Pingu"",""born"":1986}";
   
   Penguin : JSON_Value := Create_Object;
   Parents : JSON_Array;
begin
   Penguin.Set_Field (Field_Name => "name", 
                      Field      => "Linux");
   
   Penguin.Set_Field (Field_Name => "born",
                      Field      => 1992);
   
   Append (Parents, Create ("Linus Torvalds"));
   Append (Parents, Create ("Alan Cox"));
   Append (Parents, Create ("Greg Kroah-Hartman"));
 
   Penguin.Set_Field (Field_Name => "parents",
                      Field      => Parents);
   
   Put_Line (Penguin.Write);

   Penguin := Read (JSON_String, "json.errors");
   
   Penguin.Set_Field (Field_Name => "born",
                      Field      => 1986);
   
   Parents := Empty_Array;
   Append (Parents, Create ("Otmar Gutmann"));
   Append (Parents, Create ("Silvio Mazzola"));  
   
   Penguin.Set_Field (Field_Name => "parents",
                      Field      => Parents);
   
   Put_Line (Penguin.Write);
end JSON_Test;
Task: JSON




Go: package main

import "encoding/json"
import "fmt"

func main() {
    var data interface{}
    err := json.Unmarshal([]byte(`{"foo":1, "bar":[10, "apples"]}`), &data)
    if err == nil {
        fmt.Println(data)
    } else {
        fmt.Println(err)
    }

    sample := map[string]interface{}{
        "blue":  []interface{}{1, 2},
        "ocean": "water",
    }
    json_string, err := json.Marshal(sample)
    if err == nil {
        fmt.Println(string(json_string))
    } else {
        fmt.Println(err)
    }
}








Ada: with Ada.Text_IO;
with GNATCOLL.JSON;
 
procedure JSON_Test is
   use Ada.Text_IO;
   use GNATCOLL.JSON;
 
   JSON_String : constant String := "{""name"":""Pingu"",""born"":1986}";
   
   Penguin : JSON_Value := Create_Object;
   Parents : JSON_Array;
begin
   Penguin.Set_Field (Field_Name => "name", 
                      Field      => "Linux");
   
   Penguin.Set_Field (Field_Name => "born",
                      Field      => 1992);
   
   Append (Parents, Create ("Linus Torvalds"));
   Append (Parents, Create ("Alan Cox"));
   Append (Parents, Create ("Greg Kroah-Hartman"));
 
   Penguin.Set_Field (Field_Name => "parents",
                      Field      => Parents);
   
   Put_Line (Penguin.Write);

   Penguin := Read (JSON_String, "json.errors");
   
   Penguin.Set_Field (Field_Name => "born",
                      Field      => 1986);
   
   Parents := Empty_Array;
   Append (Parents, Create ("Otmar Gutmann"));
   Append (Parents, Create ("Silvio Mazzola"));  
   
   Penguin.Set_Field (Field_Name => "parents",
                      Field      => Parents);
   
   Put_Line (Penguin.Write);
end JSON_Test;
Task: JSON





Java: 



grammar JSON ;
@members {
String Indent = "";
}
Number	:	(('0')|('-'? ('1'..'9') ('0'..'9')*)) ('.' ('0'..'9')+)? (('e'|'E') ('+'|'-')? ('0'..'9')+)?;
WS	:	(' ' | '\t' | '\r' |'\n') {skip();};
Tz	:	' ' .. '!' | '#' .. '[' | ']' .. '~';
Control	:	'\\' ('"'|'\\'|'/'|'b'|'f'|'n'|'r'|'t'|UCode);
UCode	:	'u' ('0'..'9'|'a'..'f'|'A'..'F') ('0'..'9'|'a'..'f'|'A'..'F') ('0'..'9'|'a'..'f'|'A'..'F') ('0'..'9'|'a'..'f'|'A'..'F');
Keyword	:	'true' | 'false' | 'null';
String	:	'"' (Control? Tz)* '"';
object	:       '{' {System.out.println(Indent + "{Object}"); Indent += "    ";} (pair (',' pair*)*)? '}' {Indent = Indent.substring(4);};
pair	:	e = String {System.out.println(Indent + "{Property}\t" + $e.text);} ':' value;
value	:	Number             {System.out.println(Indent + "{Number}  \t" + $Number.text);}
	|	object
	|	String             {System.out.println(Indent + "{String}  \t" + $String.text);}
	|	Keyword            {System.out.println(Indent + "{Keyword} \t" + $Keyword.text);}
	|	array;
array	:	'[' {System.out.println(Indent + "Array"); Indent += "    ";} (value (',' value)*)? ']' {Indent = Indent.substring(4);};







Ada: with Ada.Text_IO;
with GNATCOLL.JSON;
 
procedure JSON_Test is
   use Ada.Text_IO;
   use GNATCOLL.JSON;
 
   JSON_String : constant String := "{""name"":""Pingu"",""born"":1986}";
   
   Penguin : JSON_Value := Create_Object;
   Parents : JSON_Array;
begin
   Penguin.Set_Field (Field_Name => "name", 
                      Field      => "Linux");
   
   Penguin.Set_Field (Field_Name => "born",
                      Field      => 1992);
   
   Append (Parents, Create ("Linus Torvalds"));
   Append (Parents, Create ("Alan Cox"));
   Append (Parents, Create ("Greg Kroah-Hartman"));
 
   Penguin.Set_Field (Field_Name => "parents",
                      Field      => Parents);
   
   Put_Line (Penguin.Write);

   Penguin := Read (JSON_String, "json.errors");
   
   Penguin.Set_Field (Field_Name => "born",
                      Field      => 1986);
   
   Parents := Empty_Array;
   Append (Parents, Create ("Otmar Gutmann"));
   Append (Parents, Create ("Silvio Mazzola"));  
   
   Penguin.Set_Field (Field_Name => "parents",
                      Field      => Parents);
   
   Put_Line (Penguin.Write);
end JSON_Test;
Task: JSON







Python: >>> import json
>>> data = json.loads('{ "foo": 1, "bar": [10, "apples"] }')
>>> sample = { "blue": [1,2], "ocean": "water" }
>>> json_string = json.dumps(sample)
>>> json_string
'{"blue": [1, 2], "ocean": "water"}'
>>> sample
{'blue': [1, 2], 'ocean': 'water'}
>>> data
{'foo': 1, 'bar': [10, 'apples']}





Ada: with Ada.Text_IO;
with GNATCOLL.JSON;
 
procedure JSON_Test is
   use Ada.Text_IO;
   use GNATCOLL.JSON;
 
   JSON_String : constant String := "{""name"":""Pingu"",""born"":1986}";
   
   Penguin : JSON_Value := Create_Object;
   Parents : JSON_Array;
begin
   Penguin.Set_Field (Field_Name => "name", 
                      Field      => "Linux");
   
   Penguin.Set_Field (Field_Name => "born",
                      Field      => 1992);
   
   Append (Parents, Create ("Linus Torvalds"));
   Append (Parents, Create ("Alan Cox"));
   Append (Parents, Create ("Greg Kroah-Hartman"));
 
   Penguin.Set_Field (Field_Name => "parents",
                      Field      => Parents);
   
   Put_Line (Penguin.Write);

   Penguin := Read (JSON_String, "json.errors");
   
   Penguin.Set_Field (Field_Name => "born",
                      Field      => 1986);
   
   Parents := Empty_Array;
   Append (Parents, Create ("Otmar Gutmann"));
   Append (Parents, Create ("Silvio Mazzola"));  
   
   Penguin.Set_Field (Field_Name => "parents",
                      Field      => Parents);
   
   Put_Line (Penguin.Write);
end JSON_Test;
Task: JSON



C#: using System;
using System.Collections.Generic;
using System.Web.Script.Serialization;

class Program
{
    static void Main()
    {
        var people = new Dictionary<string, object> {{"1", "John"}, {"2", "Susan"}};
        var serializer = new JavaScriptSerializer();
        
        var json = serializer.Serialize(people);
        Console.WriteLine(json);

        var deserialized = serializer.Deserialize<Dictionary<string, object>>(json);
        Console.WriteLine(deserialized["2"]);

        var jsonObject = serializer.DeserializeObject(@"{ ""foo"": 1, ""bar"": [10, ""apples""] }");
        var data = jsonObject as Dictionary<string, object>;
        var array = data["bar"] as object[];
        Console.WriteLine(array[1]);
    }
}
Task: JSON


C++: #include "Core/Core.h"

using namespace Upp;

CONSOLE_APP_MAIN
{
	JsonArray a;
	a << Json("name", "John")("phone", "1234567") << Json("name", "Susan")("phone", "654321");
	String txt = ~a;
	Cout() << txt << '\n';
	Value v = ParseJSON(txt);
	for(int i = 0; i < v.GetCount(); i++)
		Cout() << v[i]["name"] << ' ' << v[i]["phone"] << '\n';
}