json_array_arg in not defined #319
Unanswered
Priyaankaa13
asked this question in
Show and tell
Replies: 2 comments 5 replies
-
or as often in the examples
|
Beta Was this translation helpful? Give feedback.
4 replies
-
Like this, #include <jsoncons/json.hpp>
using jsoncons::json;
int main()
{
json image_sizing[5];
int project_no[5] = { 1, 2, 3, 4, 5 };
std::string project_name[5] = {"XXX", "YYY", "ZZZ", "PPP", "RRR"};
for (std::size_t i = 0; i < 5; ++i)
{
image_sizing[i].insert_or_assign("Project Number", project_no[i]);
image_sizing[i].insert_or_assign("Project Name", project_name[i]);
}
std::string output;
jsoncons::json_string_encoder encoder(output);
encoder.begin_object();
encoder.key("Projects");
encoder.begin_array();
for (std::size_t i = 0; i < 5; ++i)
{
image_sizing[i].dump(encoder);
}
encoder.end_array();
encoder.end_object();
encoder.flush();
std::cout << output << "\n\n";
} Or like this: #include <jsoncons/json.hpp>
using jsoncons::json;
int main()
{
json image_sizing(jsoncons::json_array_arg);
image_sizing.resize(5);
int project_no[5] = { 1, 2, 3, 4, 5 };
std::string project_name[5] = {"XXX", "YYY", "ZZZ", "PPP", "RRR"};
for (std::size_t i = 0; i < 5; ++i)
{
image_sizing[i].insert_or_assign("Project Number", project_no[i]);
image_sizing[i].insert_or_assign("Project Name", project_name[i]);
}
json projects;
projects.try_emplace("Projects", std::move(image_sizing));
std::cout << pretty_print(projects) << "\n\n";
} The output is {
"Projects": [
{
"Project Name": "XXX",
"Project Number": 1
},
{
"Project Name": "YYY",
"Project Number": 2
},
{
"Project Name": "ZZZ",
"Project Number": 3
},
{
"Project Name": "PPP",
"Project Number": 4
},
{
"Project Name": "RRR",
"Project Number": 5
}
]
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hai.,
json image_formats(json_array_arg, {"JPEG","PSD","TIFF","DNG"});
I used the above statement to create a new array in visual studio but ended up having json_array_arg in not defined exception, since i'm new to this, can anyone pls help me in this ?
Beta Was this translation helpful? Give feedback.
All reactions