Am 25.04.2013 11:47, schrieb Jean-Michel Caricand:
> Hello,
>
> I have this json string : { "a": 10, "b": { "c": "AZERTY", "d": "QWERTY" } }
>
> Without struct or C++ class, I want to get b's value as std::string. I
> tried :
>
> #include <iostream>
> #include <fstream>
> #include <cxxtools/jsondeserializer.h>
>
> int main()
> {
> std::string s("{ \"a\": 10, \"b\": { \"c\": \"AZERTY\", \"d\":
> \"QWERTY\" } }");
> std::stringstream is(s);
> cxxtools::JsonDeserializer deserializer(is);
>
> cxxtools::SerializationInfo si;
> deserializer.deserialize(si, "b");
>
> std::string b1;
> si.getMember("c") >>= b1; // ----> OK :)
>
> std::cout << "b1: " << b1 << std::endl;
>
> std::string b2;
> deserializer.deserialize(b2, "b"); // ----> NOT OK, b2 is empty :(
>
> std::cout << "b2: " << b2 << std::endl;
> }
>
> Is it possible to get b's value as string ?
>
> Thanks,
>
> Jean-Michel
>
Hi,
I don't quite understand, what you try to achieve. "b" is not a string
but a structure. How do you expect to get it as a string?
Do you expect to get it as a json string? Then you need to serialize the
si back to json using json serializer. Note that the SerializationInfo
do not have any information about the original format but just holds the
structure. Try this:
std::ostringstream os;
cxxtools::JsonSerializer serializer(os);
serializer.serialize(si)
.finish();
std::string b2 = os.str();
std::cout << "b2: " << b2 << std::endl;
Tommi
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general