langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
24
Task/JSON/OCaml/json-1.ocaml
Normal file
24
Task/JSON/OCaml/json-1.ocaml
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
type json item =
|
||||
< name "Name": string;
|
||||
kingdom "Kingdom": string;
|
||||
phylum "Phylum": string;
|
||||
class_ "Class": string;
|
||||
order "Order": string;
|
||||
family "Family": string;
|
||||
tribe "Tribe": string
|
||||
>
|
||||
|
||||
let str = "
|
||||
{
|
||||
\"Name\": \"camel\",
|
||||
\"Kingdom\": \"Animalia\",
|
||||
\"Phylum\": \"Chordata\",
|
||||
\"Class\": \"Mammalia\",
|
||||
\"Order\": \"Artiodactyla\",
|
||||
\"Family\": \"Camelidae\",
|
||||
\"Tribe\": \"Camelini\"
|
||||
}"
|
||||
|
||||
let () =
|
||||
let j = Json_io.json_of_string str in
|
||||
print_endline (Json_io.string_of_json j);
|
||||
31
Task/JSON/OCaml/json-2.ocaml
Normal file
31
Task/JSON/OCaml/json-2.ocaml
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
open Yojson.Basic.Util
|
||||
|
||||
let s = "
|
||||
{ \"name\": \"John Doe\",
|
||||
\"pages\": [
|
||||
{ \"id\": 1,
|
||||
\"title\": \"The Art of Flipping Coins\",
|
||||
\"url\": \"http://example.com/398eb027/1\"
|
||||
},
|
||||
{ \"id\": 2, \"deleted\": true },
|
||||
{ \"id\": 3,
|
||||
\"title\": \"Artichoke Salad\",
|
||||
\"url\": \"http://example.com/398eb027/3\"
|
||||
},
|
||||
{ \"id\": 4,
|
||||
\"title\": \"Flying Bananas\",
|
||||
\"url\": \"http://example.com/398eb027/4\"
|
||||
}
|
||||
]
|
||||
}"
|
||||
|
||||
let extract_titles json =
|
||||
[json]
|
||||
|> filter_member "pages"
|
||||
|> flatten
|
||||
|> filter_member "title"
|
||||
|> filter_string
|
||||
|
||||
let () =
|
||||
let json = Yojson.Basic.from_string s in
|
||||
List.iter print_endline (extract_titles json)
|
||||
Loading…
Add table
Add a link
Reference in a new issue