#include "json.hpp"
#include <iostream>
using json = nlohmann::json;
int main()
{
auto j{json::parse(R"({ "result": [1, 2, 3] })")};
std::cout << j["result"];
return 0;
}
compiled with g++5, g++6, gcc+7 bring to the following result:
terminate called after throwing an instance of 'nlohmann::detail::type_error'
what(): [json.exception.type_error.305] cannot use operator[] with array
with clang++ the output is the excepted:
[1, 2, 3]
I'm using json 3.1.2, is there an error in my code? what compiler is wrong? can we obtain the same behaviour on both the family complier?
The code works in the on either g++ and clang++ if I use the assignment instead of braced initialisation.
so:
auto j{json::parse(R"({ "result": [1, 2, 3] })")};
std::cout << j["result"];
works on clang
auto j = json::parse(R"({ "result": [1, 2, 3] })");
std::cout << j["result"];
works on both family compilers
auto j{json::parse(R"({ "result": [1, 2, 3] })")};
std::cout << j[0]["result"];
works on g++
thank you for the support!
compiled with g++5, g++6, gcc+7 bring to the following result:
terminate called after throwing an instance of 'nlohmann::detail::type_error'
what(): [json.exception.type_error.305] cannot use operator[] with array
with clang++ the output is the excepted:
[1, 2, 3]
I'm using json 3.1.2, is there an error in my code? what compiler is wrong? can we obtain the same behaviour on both the family complier?
The code works in the on either g++ and clang++ if I use the assignment instead of braced initialisation.
so:
works on clang
works on both family compilers
works on g++
thank you for the support!