JSON String Conversion Problems.

Aug 8, 2013 at 11:42 AM
Hopefully someone can help me out here. I'm using Casablanca on Windows Phone 8, and have the following issue.

json::value v;
v[L"Hello"] = json::value::string(U("World"))

client.request(methods::POST,L"",v.to_string(),L"applications/json").then[](http_response response) {
// more code here

Delivers the following to my server:
{u'Hello' : u'World'}

Which is not valid JSON. Is there any special magical incantations I need to use to correctly format the data for uploading?
Aug 8, 2013 at 3:46 PM
Edited Aug 8, 2013 at 3:54 PM
No kidding! That's very strange. Let me see if I can reproduce it here.

BTW, "applications/json" isn't a proper MIME type -- it should be "application/json". That isn't likely to be the problem, though.

Aug 8, 2013 at 3:57 PM
Cheers. I'm running a web2py as my backend, if that helps you re-create. And good catch on the MIME type...the error crept in when I transcribed from editor on one machine to browser window on other...it's actually correct in the code :)
Aug 8, 2013 at 3:59 PM
Edited Aug 8, 2013 at 4:05 PM
I can't reproduce this. I get the expected { "Hello" : "World" } when I use the WP8 library to create a JSON payload. BTW, you don't have to serialize to a string yourself, you can just use the request() overload that takes a JSON value:
json::value v; 
v[L"Hello"] = json::value::string(U("World")); 

client.request(methods::POST, L"", v).then[](http_response response) { 
    // more code here 
If you try it with a Windows desktop or app store app, what happens? Can you use fiddler with the emulator to see what actually is sent on the wire?

Are you using some locale other than Western European? We haven't tested on a lot of non-WE locales (Japan is the only East Asian we've tried things on, I believe, for example).
Aug 8, 2013 at 4:27 PM
Thanks for the tip on the no-need-to-serialize. I've not tried it in a desktop app store app, but will give it a go.

I can't use fiddler, because when I switch to Emulator I get "error LNK1112: module machine type 'ARM' conflicts with target machine type 'X86'" on cpprest110_wp8_1_1.lib (but that's a separate issue ;))
Aug 8, 2013 at 4:31 PM
But Language is English, Region is Denmark. That shouldn't affect it.
Aug 8, 2013 at 4:33 PM
It is a different issue, but it complicates troubleshooting the first one.

It means something's wacky in your setup -- the link path is referring to the ARM lib even though you've switched to X86 (the emulator configuration). What does the 'Additional Library Directories' property in the Linker|General sheet say when you switch to X86? Did you set up references manually, or include it by reference to the WP8 Extension SDK?
Aug 8, 2013 at 5:15 PM
So I set it up manually, and yups I can see the problem there.

I used the Framework and References way of adding CppRESTWindowsSDK to my project, but it didn't pull in the additional libs and I took the lazy route to getting them in there. I have to call it a day for today, but I'll look at what fiddler says is being sent tomorrow.

Thanks for the help, and the library!