Hi Sebastian,
the secret is to set the category of the cxxtools::SerialzationInfo to
Array and omit the name name like this:
void operator<<= (cxxtools::SerializationInfo& si, const ParticleFlight& pf)
{
si.addMember() <<= pf.type;
si.addMember() <<= pf.energy;
si.setCategory(cxxtools::SerializationInfo::Array);
}
When I follow your example it results in this json structure:
[["e",78.90000152587890625],["g",1234.56005859375]]
Note that the float has a quite significant rounding error. The literal
78.9 is converted to a double internally and the converted back to decimal.
Tommi
Am 23.04.2014 13:54, schrieb Sebastian Schoene:
Hi List,
I'm sure this is a trivial question, but ... you know ;-)
I need to serialize variables of different data types into one unnamed
list.
Minimal example:
=== === === ===
struct ParticleFlight{
char type;
float energy;
}
void operator<<= (cxxtools::SerializationInfo& si, const
ParticleFlight& pf) {
??????????
}
=== === === ===
... for JSON a datum
pf={'e', 511.2};
should result in
{"jsonrpc": "2.0", "result": ['e', 511.2], "id": 4}
and
v=vector<ParticleFlight>();
v.push_back({'e', 78.9});
v.push_back({'g', 1234.56});
in
{"jsonrpc": "2.0", "result": [ ['e', 78.9], ['g', 1234.56]], "id": 4}
According to the docs "An |Array| is just a list of unnamed values."
but how to use?
Thanks ,
Sebastian
------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general
------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general