De/Serialisation of vector of tupple object with nested obect need Help please #1794
Closed
Description
first thank for your library is amazing.
- Describe what you want to achieve.
i want to parse data raw json to object with to_json and from_json
i want to parse vector of tupple of object on my object architecure
to_json work fine and without problem but in reverse from_json.
"DATA" : [
{
"ObjectA": {
"attriA1": 0,
"ObjectD":{
"id": 0,
"lat": 110,
},
"attriA2": 220
},
"ObjectB": {
...
},
"ObjectC": {
...
}
},
{
"ObjectA": {
"attriA1": 0,
"ObjectD":{
"id": 0,
"lat": 110,
},
"attriA2": 220
},
"ObjectB": {
...
},
"ObjectC": {
...
}
}
],
..
- Describe what you tried.
i have tried to with differenct ObjectA, ObjectB,ObjectC, ObjectD
void from_json(const json& jsonData, ObjectA& a)
{
//set functions
..
}
static void to_json(json& jsonData, const ObjectA& a)
{
.....
}
.her is my Code
typedef std::vector<std::tuple<ObjectA, ObjectB, ObjectC> > myTupple;
for (auto &i : jsonUser.at("DATA").get<myTupple>()); **// her is compiler error**
{
std::cout<<"test"<<'\n';
/* user.DeviceActionList(*i.begin()); */
}
_output from compiler error:_
erminate called after throwing an instance of 'nlohmann::detail::type_error'
what(): [json.exception.type_error.304] cannot use at() with object
Thread 1 "Rdc4BackkendIot" received signal SIGABRT, Aborted.
0x00007ffff606b428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
54 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
GDB infor
0 0x00007ffff606b428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#1 0x00007ffff606d02a in __GI_abort () at abort.c:89
#2 0x00007ffff66a90f5 in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007ffff66a6ce6 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ffff66a6d31 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007ffff66a6f74 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x0000000000465716 in nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>::at (this=0x8032a0, idx=2) at ./nlohmann/json.hpp:12987
#7 0x0000000000464cab in nlohmann::detail::from_json_tuple_impl<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>, std::tuple<Device, Permission, Notification>, 0ul, 1ul, 2ul> (j=..., t=std::tuple containing = {...})
at ./nlohmann/json.hpp:1270
#8 0x0000000000464165 in nlohmann::detail::from_json<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>, Device, Permission, Notification> (j=..., t=std::tuple containing = {...}) at ./nlohmann/json.hpp:1276
#9 0x0000000000463555 in nlohmann::detail::from_json_fn::call<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>, std::tuple<Device, Permission, Notification> > (
this=0x555a20 <nlohmann::detail::static_const<nlohmann::detail::from_json_fn>::value>, j=..., val=std::tuple containing = {...}) at ./nlohmann/json.hpp:1302
#10 0x000000000046243b in nlohmann::detail::from_json_fn::operator()<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>, std::tuple<Device, Permission, Notification> > (
this=0x555a20 <nlohmann::detail::static_const<nlohmann::detail::from_json_fn>::value>, j=..., val=std::tuple containing = {...}) at ./nlohmann/json.hpp:1326
#11 0x00000000004605d2 in nlohmann::adl_serializer<std::tuple<Device, Permission, Notification>, void>::from_json<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> const&, std::tuple<Device, Permission, Notification> > (j=...,
val=std::tuple containing = {...}) at ./nlohmann/json.hpp:10144
#12 0x000000000045d79f in nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>::get<std::tuple<Device, Permission, Notification>, std::tuple<Device, Permission, Notification>, 0> (this=0x8032a0) at ./nlohmann/json.hpp:12631
#13 0x0000000000459e7e in decltype ((({parm#2}.reserve)((declval<std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > >::size_type>)())),((void)())) nlohmann::detail::from_json_array_impl<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>, std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > > >(nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> const&, std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > >&, nlohmann::detail::priority_tag<1u>)::{lambda(nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> const&)#1}::operator()(nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> const&) const (__closure=0x7fffffffc030, i=...) at ./nlohmann/json.hpp:1173
#14 0x000000000045d842 in std::transform<nlohmann::detail::iter_impl<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> const>, std::insert_iterator<std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > > >, decltype ((({parm#2}.reserve)((declval<std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > >::size_type>)())),((void)())) nlohmann::detail::from_json_array_impl<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>, std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > > >(nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> const&, std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > >&, nlohmann::detail::priority_tag<1u>)::{lambda(nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> const&)#1}>(nlohmann::detail::iter_impl<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> const>, nlohmann::detail::iter_impl<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> const>, std::insert_iterator<std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > > >, decltype ((({parm#2}.reserve)((declval<std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > >::size_type>)())),((void)())) nlohmann::detail::from_json_array_impl<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>, std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > > >(nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> const&, std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > >&, nlohmann::detail::priority_tag<1u>)::{lambda(nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> const&)#1}) (__first=..., __last=..., __result=..., __unary_op=...) at /usr/include/c++/7/bits/stl_algo.h:4306
#15 0x0000000000459fac in nlohmann::detail::from_json_array_impl<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, ---Type <return> to continue, or q <return> to quit---
long, unsigned long, double, std::allocator, nlohmann::adl_serializer>, std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > > >
(j=..., arr=std::vector of length 0, capacity 1) at ./nlohmann/json.hpp:1167
#16 0x0000000000454fe7 in nlohmann::detail::from_json<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>, std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > >, 0> (j=...,
arr=std::vector of length 0, capacity 1) at ./nlohmann/json.hpp:1195
#17 0x000000000044cecd in nlohmann::detail::from_json_fn::call<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>, std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > > > (
this=0x555a20 <nlohmann::detail::static_const<nlohmann::detail::from_json_fn>::value>, j=..., val=std::vector of length 0, capacity 1) at ./nlohmann/json.hpp:1302
#18 0x0000000000444b03 in nlohmann::detail::from_json_fn::operator()<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>, std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > > > (this=0x555a20 <nlohmann::detail::static_const<nlohmann::detail::from_json_fn>::value>, j=..., val=std::vector of length 0, capacity 1) at ./nlohmann/json.hpp:1326
#19 0x0000000000439a38 in nlohmann::adl_serializer<std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > >, void>::from_json<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> const&, std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > > > (j=..., val=std::vector of length 0, capacity 1)
at ./nlohmann/json.hpp:10144
#20 0x0000000000431285 in nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>::get<std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > >, std::vector<std::tuple<Device, Permission, Notification>, std::allocator<std::tuple<Device, Permission, Notification> > >, 0> (this=0x837750) at ./nlohmann/json.hpp:12631
#21 0x000000000040ef20 in from_json (jsonUser=..., user=...) at ./include/JsonSerialiser.h:87
#22 0x000000000044dcf7 in nlohmann::detail::from_json_fn::call<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>, User> (this=0x555a20 <nlohmann::detail::static_const<nlohmann::detail::from_json_fn>::value>, j=..., val=...)
at ./nlohmann/json.hpp:1302
#23 0x000000000044578f in nlohmann::detail::from_json_fn::operator()<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>, User> (this=0x555a20 <nlohmann::detail::static_const<nlohmann::detail::from_json_fn>::value>, j=..., val=...)
at ./nlohmann/json.hpp:1326
#24 0x000000000043a45a in nlohmann::adl_serializer<User, void>::from_json<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> const&, User> (j=..., val=...) at ./nlohmann/json.hpp:10144
#25 0x0000000000431c0d in nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>::get<User, User, 0> (this=0x837680) at ./nlohmann/json.hpp:12631