views:

31

answers:

1

Hey all,

I send a list over JSON to my server where it updates it and sends me back the updated list. But when I receive the response I get back some weird JSON:

ResponseString from Server: {"d":"{\"basketList\":[{\"amount\":1,\"strikethrough\":0,\"listName\":\"default\",\"listID\":\"00000000-0000-0000-0000-000000000000\",\"TimeStamp\":\"10/10/01 09:17:08\",\"id\":\"4116858a-374b-489b-ae26-5175b7b7b0f9\",\"thumb\":\"http://mobile.boxolino.com/test/60aee80d-ad31-49b1-9895-4984fa348624_56x56.png\",\"name\":\"0,5L ROOMIJS CHOCOLADE\",\"image\":\"\",\"type\":\"product\",\"isPromo\":0,\"inList\":1,\"rotatorImage\":\"\",\"expiration\":\"01/01/10\",\"brand\":\"\",\"enseigne\":\"\",\"branch\":\"\",\"branchID\":\"00000000-0000-0000-0000-000000000000\"},{\"amount\":1,\"strikethrough\":0,\"listName\":\"default\",\"listID\":\"00000000-0000-0000-0000-000000000000\",\"TimeStamp\":\"10/10/01 09:17:08\",\"id\":\"4fbc4d31-ca2a-4001-942b-6da270de7eb4\",\"thumb\":\"http://mobile.boxolino.com/test/60aee80d-ad31-49b1-9895-4984fa348624_56x56.png\",\"name\":\"Biokatoenen washandjes 4 stuks - 16 x 21 cm\",\"image\":\"\",\"type\":\"product\",\"isPromo\":0,\"inList\":1,\"rotatorImage\":\"\",\"expiration\":\"01/01/10\",\"brand\":\"\",\"enseigne\":\"\",\"branch\":\"\",\"branchID\":\"00000000-0000-0000-0000-000000000000\"},{\"amount\":14,\"strikethrough\":0,\"listName\":\"default\",\"listID\":\"00000000-0000-0000-0000-000000000000\",\"TimeStamp\":\"10/10/01 09:17:08\",\"id\":\"e410e57c-2d0b-4486-98f8-a350490eab85\",\"thumb\":\"http://mobile.boxolino.com/test/60aee80d-ad31-49b1-9895-4984fa348624_56x56.png\",\"name\":\"Parelhoen prijs/kg\",\"image\":\"\",\"type\":\"product\",\"isPromo\":0,\"inList\":14,\"rotatorImage\":\"\",\"expiration\":\"01/01/10\",\"brand\":\"\",\"enseigne\":\"\",\"branch\":\"\",\"branchID\":\"00000000-0000-0000-0000-000000000000\"},{\"amount\":1,\"strikethrough\":1,\"listName\":\"default\",\"listID\":\"00000000-0000-0000-0000-000000000000\",\"TimeStamp\":\"10/10/01 09:17:08\",\"id\":\"7798392f-d47d-48b1-a368-c3d65dcb1523\",\"thumb\":\"http://mobile.boxolino.com/test/60aee80d-ad31-49b1-9895-4984fa348624_56x56.png\",\"name\":\"6 WASHANDJES +KAART M.BLAUW\",\"image\":\"\",\"type\":\"product\",\"isPromo\":0,\"inList\":1,\"rotatorImage\":\"\",\"expiration\":\"01/01/10\",\"brand\":\"\",\"enseigne\":\"\",\"branch\":\"\",\"branchID\":\"00000000-0000-0000-0000-000000000000\"},{\"amount\":7,\"strikethrough\":0,\"listName\":\"default\",\"listID\":\"00000000-0000-0000-0000-000000000000\",\"TimeStamp\":\"10/10/01 09:17:08\",\"id\":\"2e3040a1-2c6e-469c-8f09-d4bc58eda5df\",\"thumb\":\"http://mobile.boxolino.com/test/60aee80d-ad31-49b1-9895-4984fa348624_56x56.png\",\"name\":\"Hydraterend scheerapparaat HS8420\",\"image\":\"\",\"type\":\"product\",\"isPromo\":0,\"inList\":7,\"rotatorImage\":\"\",\"expiration\":\"01/01/10\",\"brand\":\"\",\"enseigne\":\"\",\"branch\":\"\",\"branchID\":\"00000000-0000-0000-0000-000000000000\"},{\"amount\":1,\"strikethrough\":0,\"listName\":\"default\",\"listID\":\"00000000-0000-0000-0000-000000000000\",\"TimeStamp\":\"10/10/01 09:17:08\",\"id\":\"fccf42c8-8c86-43b7-aca7-df05dd3cf85f\",\"thumb\":\"http://mobile.boxolino.com/test/60aee80d-ad31-49b1-9895-4984fa348624_56x56.png\",\"name\":\"Varkensgebraad prijs/kg \",\"image\":\"\",\"type\":\"product\",\"isPromo\":0,\"inList\":1,\"rotatorImage\":\"\",\"expiration\":\"01/01/10\",\"brand\":\"\",\"enseigne\":\"\",\"branch\":\"\",\"branchID\":\"00000000-0000-0000-0000-000000000000\"},{\"amount\":4,\"strikethrough\":0,\"listName\":\"default\",\"listID\":\"00000000-0000-0000-0000-000000000000\",\"TimeStamp\":\"10/10/01 09:17:08\",\"id\":\"cfcdd1e9-cd52-4884-9cf0-e54f98f33c2f\",\"thumb\":\"http://mobile.boxolino.com/test/60aee80d-ad31-49b1-9895-4984fa348624_56x56.png\",\"name\":\"Rok met print mt 36-46\",\"image\":\"\",\"type\":\"product\",\"isPromo\":1,\"inList\":4,\"rotatorImage\":\"\",\"expiration\":\"01/01/10\",\"brand\":\"\",\"enseigne\":\"\",\"branch\":\"Rokken\",\"branchID\":\"f49ac233-5d53-4340-8b89-cae9a285c032\"}]}"}

The normal output should be without that "d" and all the backslashes...

Any idea what is going on?

How I got this output:

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    NSLog(@"ResponseString from Server: %@",responseString);

Thanks in advance,

Lewion

+1  A: 

It is probably related to the son module in the server and not the son module in the iPhone.

There are many ways to solve it. For example: 1. Replace the \" with " and after getting the JSON object get the value of the key "d" as the final object, 2. Try looking on the son module in the server and either try to config it to have a different configuration or replace it with a better one.

If you need help on the second option you'll need to post more data related to the server.

Guy Ephraim
The problem isn't on the server side the output from the server is without the "d" object. The backslashes are probably normal because I print it out as a string and otherwise you can't put double quotes in a string... just that "d" bugs me :S
Lewion
By looking at your code, there is not transformation done on the data, so the "d" is either added at the server side or there is some work done on the data before the code segment you posted.
Guy Ephraim
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; NSLog(@"ResponseString from Server: %@",responseString); The data comes directly from the response... responseData is added with the data from the response and on finish I put it in a NSString and show it..
Lewion
As I said, if this is all of the work done on the iPhone then the server is adding the "d", try accessing the URL you get the son from using a regular browser(if it is over http) or some kind of sniffer, and see that the server is returning the "d"
Guy Ephraim
No "d"... I seriously don't know where that "d" comes from... :S could it be a wrong content type of the response? Although it shows correctly in a web browser...
Lewion
The only other thing I can think of is, that the server return different result to the iPhone and the browser, it might be content type or user agent or other things, try sniffing the result when using the iPhone and the browser to understand the difference
Guy Ephraim
I appreciate your answers. I'll look into it. Thanks already :)
Lewion
Try looking at the following answer http://stackoverflow.com/questions/1625500/jsonconvert-deserializeobject-and-d-wrapper-in-wcf
Guy Ephraim
Thanks. I'm going to select this answer as my accepted answer.
Lewion