Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De/Serialisation of vector of tupple object with nested obect need Help please #1794

Closed
bnadem opened this issue Oct 15, 2019 · 1 comment
Closed
Labels
kind: question state: needs more info the author of the issue needs to provide more details

Comments

@bnadem
Copy link

bnadem commented Oct 15, 2019

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
@nlohmann
Copy link
Owner

Can you please provide more example code - best would be a compilable example.

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Oct 17, 2019
@nlohmann nlohmann closed this as completed Nov 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question state: needs more info the author of the issue needs to provide more details
Projects
None yet
Development

No branches or pull requests

2 participants