Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » How do I deserialize grouped items into an array or map when they take this form? [solved]
How do I deserialize grouped items into an array or map when they take this form? [solved] [message #58329] Tue, 26 April 2022 01:49 Go to next message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 144
Registered: June 2011
Experienced Member
How do I de/serialize something in the form of:

"whatever": {
   "Item A": {
      "member A": "whatever",
      "member B": "whatever"
   },
   "Item B": {
      "member A": "whatever",
      "member B": "whatever"
   },
   ...
}


when it's not in the form of an array/list, etc and the key isn't known ahead of time?

Map wants to create fields called key/value instead making "Item A", "Item B", ... keys and "member A", "member B" their values.

What's the appropriate structure to de/serialize this into?

[Updated on: Tue, 26 April 2022 06:29]

Report message to a moderator

Re: How do I deserialize grouped items into an array or map when they take this form? [message #58330 is a reply to message #58329] Tue, 26 April 2022 06:28 Go to previous message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 144
Registered: June 2011
Experienced Member
Never mind, I found it.

struct WhateverItem {
    String memberA {};
    String memberB {};

    void Jsonize(JsonIO& io) {
        io
        ("member A", memberA)
        ("member B", memberB);
    }
};

struct Whatever {
    using WhateverMap = VectorMap<String, WhateverItem>;
    WhateverMap whateverMap;

    void Jsonize(JsonIO& io) {
        io.Var("whatever", whateverMap, 
            [&](IO &io, WhateverMap& m) {
                StringMap(io, m);
            }
         );
    }
};   
Previous Topic: Memory management question
Next Topic: BiArray::Create{Head,Tail} with variadic args
Goto Forum:
  


Current Time: Fri Jul 01 10:17:37 CEST 2022

Total time taken to generate the page: 0.01391 seconds