This commit is contained in:
Ingy döt Net 2013-06-05 21:47:54 +00:00
parent 1f1ad49427
commit 6f050a029e
2496 changed files with 37609 additions and 3031 deletions

41
Task/JSON/Ada/json-1.ada Normal file
View file

@ -0,0 +1,41 @@
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;

41
Task/JSON/Ada/json-2.ada Normal file
View file

@ -0,0 +1,41 @@
with Ada.Wide_Wide_Text_IO; use Ada.Wide_Wide_Text_IO;
with League.JSON.Arrays; use League.JSON.Arrays;
with League.JSON.Documents; use League.JSON.Documents;
with League.JSON.Objects; use League.JSON.Objects;
with League.JSON.Values; use League.JSON.Values;
with League.Strings; use League.Strings;
procedure Main is
function "+" (Item : Wide_Wide_String) return Universal_String
renames To_Universal_String;
JSON_String : constant Universal_String
:= +"{""name"":""Pingu"",""born"":1986}";
Penguin : JSON_Object;
Parents : JSON_Array;
begin
Penguin.Insert (+"name", To_JSON_Value (+"Linux"));
Penguin.Insert (+"born", To_JSON_Value (1992));
Parents.Append (To_JSON_Value (+"Linus Torvalds"));
Parents.Append (To_JSON_Value (+"Alan Cox"));
Parents.Append (To_JSON_Value (+"Greg Kroah-Hartman"));
Penguin.Insert (+"parents", To_JSON_Value (Parents));
Put_Line (To_JSON_Document (Penguin).To_JSON.To_Wide_Wide_String);
Penguin := From_JSON (JSON_String).To_Object;
Parents := Empty_JSON_Array;
Parents.Append (To_JSON_Value (+"Otmar Gutmann"));
Parents.Append (To_JSON_Value (+"Silvio Mazzola"));
Penguin.Insert (+"parents", To_JSON_Value (Parents));
Put_Line (To_JSON_Document (Penguin).To_JSON.To_Wide_Wide_String);
end Main;

View file

@ -1,17 +1,14 @@
NSString *json_string = @"{ \"foo\": 1, \"bar\": [10, \"apples\"] }";
id obj = [NSJSONSerialization JSONObjectWithData:[json_string dataUsingEncoding:NSUTF8StringEncoding]
options:0
error:NULL];
NSString *jsonString = @"{ \"foo\": 1, \"bar\": [10, \"apples\"] }";
id obj = [NSJSONSerialization
JSONObjectWithData: [json_string dataUsingEncoding: NSUTF8StringEncoding]
options: 0
error: NULL];
NSLog(@"%@", obj);
id obj2 = [NSDictionary dictionaryWithObjectsAndKeys:[NSArray arrayWithObjects:[NSNumber numberWithInt:1],
[NSNumber numberWithInt:2],
nil],
@"blue",
@"water", @"ocean",
nil];
NSString *json_string2 = [[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:obj2
options:0
error:NULL]
encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"%@", json_string2);
NSDictionary *dict = @{ @"blue": @[@1, @2], @"ocean": @"water"};
NSData *jsonData = [NSJSONSerialization dataWithJSONObject: dict
options: 0
error: NULL];
NSString *jsonString2 = [[NSString alloc] initWithData: jsonData
encoding: NSUTF8StringEncoding];
NSLog(@"%@", jsonString2);