Le 19/03/2012 22:15, Tommi Mäkitalo a écrit :
> On 03/19/2012 10:36 AM, Jean-Michel Caricand wrote:
>> #include<iostream>
>> #include<sstream>
>> #include<cxxtools/jsonserializer.h>
>>
>> using namespace std;
>> using namespace cxxtools;
>>
>> int main(int argc, char *argv[])
>> {
>>        string s1 = "Anaïs";
>>        ostringstream o;
>>
>>        JsonSerializer serializer(o);
>>        //serializer.beautify(true);
>>        serializer.serialize(s1, "s1");
>>        serializer.finish();
>>
>>        cout<<   "s1:"<<   s1<<   endl;
>>        cout<<   "json :"<<   o.str()<<   endl;
>>
>>        return 0;
>> }
> Hi,
>
> You should use cxxtools::String, which is a std::basic_string with
> unicode. The example looks like this then:
>
> #include<iostream>
> #include<sstream>
> #include<cxxtools/jsonserializer.h>
>
> using namespace std;
> using namespace cxxtools;
>
> int main(int argc, char *argv[])
> {
>        String s1 = L"Anaïs";
>        ostringstream o;
>
>        JsonSerializer serializer(o);
>        //serializer.beautify(true);
>        serializer.serialize(s1, "s1");
>        serializer.finish();
>
>        cout<<  "s1: "<<  s1<<  endl;
>        cout<<  "json : "<<  o.str()<<  endl;
>
>        return 0;
> }
>
> And it works. Output is this here:
> $ g++ -o json -lcxxtools json.cpp
> $ ./json
> s1: Anaïs
> json : {"s1":"Ana\u00efs"}
>
> Tommi
>
> ------------------------------------------------------------------------------
> This SF email is sponsosred by:
> Try Windows Azure free for 90 days Click Here
> http://p.sf.net/sfu/sfd2d-msazure
> _______________________________________________
> Tntnet-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/tntnet-general
Hi Tommi,

Thank for your anwser :)

Why not add this example in your Wiki ? After your post, I found this on 
the Web :

int main(int argc, char **argv) {
         cxxtools::Utf8Codec codec;
         cxxtools::JsonSerializer serializer(std::cout);

         std::string test = "äöüÄÖÜß";
         std::cout << test << " - ";

         cxxtools::String out = codec.decode(test);

         std::cout << codec.encode(out);
         std::cout << "\n";

         serializer.serialize(out, "recordings");
         serializer.finish();

         std::cout << "\n";
}

It's also very good example...

Thanks,

Jean-Michel

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general

Reply via email to