2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

65
Task/JSON/C++/json-2.cpp Normal file
View file

@ -0,0 +1,65 @@
#include <iostream>
#include <iomanip> // std::setw
#include <sstream>
#include <cassert>
#include "json.hpp"
using json = nlohmann::json;
int main( int argc, char* argv[] )
{
std::string const expected =
R"delim123({
"answer": {
"everything": 42
},
"happy": true,
"list": [
1,
0,
2
],
"name": "Niels",
"nothing": null,
"object": {
"currency": "USD",
"value": 42.99
},
"pi": 3.141
})delim123";
json const jexpected = json::parse( expected );
assert( jexpected["list"][1].get<int>() == 0 );
assert( jexpected["object"]["currency"] == "USD" );
json jhandmade = {
{"pi", 3.141},
{"happy", true},
{"name", "Niels"},
{"nothing", nullptr},
{"answer", {
{"everything", 42}
}
},
{"list", {1, 0, 2}},
{"object", {
{"currency", "USD"},
{"value", 42.99}
}
}
};
assert( jexpected == jhandmade );
std::stringstream jhandmade_stream;
jhandmade_stream << std::setw(4) << jhandmade;
std::string jhandmade_string = jhandmade.dump(4);
assert( jhandmade_string == expected );
assert( jhandmade_stream.str() == expected );
return 0;
}

View file

@ -0,0 +1,13 @@
#import system.
#import extensions.
#import extensions'dynamic.
#symbol program =
[
#var json := "{ ""foo"": 1, ""bar"": [10, ""apples""] }".
#var o := json fromJson.
console writeLine:"json.foo=":(o foo).
console writeLine:"json.bar=":(o bar).
].

View file

@ -0,0 +1,4 @@
var data = JSON.parse('{ "foo": 1, "bar": [10, "apples"] }');
var sample = { "blue": [1,2], "ocean": "water" };
var json_string = JSON.stringify(sample);

View file

@ -1,8 +1,8 @@
require 'json'
ruby_obj = JSON.parse('{"blue": [1, 2], "ocean": "water"}')
p ruby_obj
puts ruby_obj.class
puts ruby_obj["blue"].class
ruby_obj["ocean"] = {"water" => %w{fishy salty}}
puts ruby_obj
ruby_obj["ocean"] = { "water" => ["fishy", "salty"] }
puts JSON.generate(ruby_obj)
puts JSON.pretty_generate(ruby_obj)