Esempio n. 1
0
void more_examples()
{
    json image_sizing;
	image_sizing["resize_to_fit"] = true;  // a boolean 
	image_sizing["resize_unit"] =  "pixels";  // a string
	image_sizing["resize_what"] =  "long_edge";  // a string
	image_sizing["dimension1"] = 9.84;  // a double
	image_sizing["dimension2"] = jsoncons::null_type();  // a null value
    std::cout << pretty_print(image_sizing) << std::endl;

    json image_formats = json::make_array();
    image_formats.add("JPEG");
    image_formats.add("PSD");
    image_formats.add("TIFF");
    image_formats.add("DNG");

    json file_export;
    file_export["image_formats"] = std::move(image_formats);
    file_export["image_sizing"] = std::move(image_sizing);
    std::cout << pretty_print(file_export) << std::endl;

    size_t n = 10, m = 3;
    std::vector<size_t> x(n, m);
    x[5] = 3;
}
Esempio n. 2
0
void read_csv_file2()
{
    string text = 
"project_id, task_name, task_start, task_finish\n"
"4001,task1,01/01/2003,01/31/2003\n"
"4001,task2,02/01/2003,02/28/2003\n"
"4001,task3,03/01/2003,03/31/2003\n"
"4002,task1,04/01/2003,04/30/2003\n"
"4002,task2,05/01/2003,";

    std::istringstream is(text);

    json_deserializer handler;

    csv_parameters params;
    params.assume_header(true);
    params.trim(true);
    params.ignore_empty_values(true);
    params.data_types("integer,string,string,string");
    csv_reader reader(is,handler,params);
    reader.read();
    json val = handler.get_result();

    std::cout << pretty_print(val) << std::endl;
}
Esempio n. 3
0
void read_csv_file1()
{
    string text = "employee-no,employee-name,dept,salary\n00000001,\"Smith,Matthew\",sales,150000.00\n00000002,\"Brown,Sarah\",sales,89000.00";

    std::istringstream is(text);

    json_deserializer handler;

    csv_parameters params;
    params.assume_header(true);
    params.data_types("string,string,string,float");
    csv_reader reader(is,handler,params);
    reader.read();
    json val = handler.get_result();

    std::cout << pretty_print(val) << std::endl;
}
void put_custom_data_in_object()
{
    json obj;
    std::vector<double> v(4);
    v[0] = 0;
    v[1] = 1;
    v[2] = 2;
    v[3] = 3;

    obj.set_custom_data("myvector",v);
    std::cout << pretty_print(obj) << std::endl;

    std::vector<double> v1 = obj["myvector"].custom_data<std::vector<double>>();
    for (size_t i = 0; i < v1.size(); ++i)
    {
        std::cout << v1[i] << " ";
    }
    std::cout << std::endl;
}
Esempio n. 5
0
void second_example_a()
{
    try
    {
        json books = json::make_array();

        {
            json book;
            book["title"] = "Kafka on the Shore";
            book["author"] = "Haruki Murakami";
            book["price"] = 25.17;
            books.add(std::move(book));
        }

        {
            json book;
            book["title"] = "Women: A Novel";
            book["author"] = "Charles Bukowski";
            book["price"] = 12.00;
            books.add(std::move(book));
        }

        {
            json book;
            book["title"] = "Cutter's Way";
            book["author"] = "Ivan Passer";
            books.add(std::move(book));
        }

        std::cout << pretty_print(books) << std::endl;
    }
    catch (const std::exception& e)
    {
        std::cerr << e.what() << std::endl;
    }
}