views:

1035

answers:

5
{"something":"1","mode":"true","number":"1234"}

Because I'm getting a 406 on expecting JSON.

It's being generated via Jersey, which is told that a method @Produces JSON. It's being received by a Dojo xhrGet which has JSON set as its handleAs.

EDIT - To clarify, I'm not interested in the code where I evaluate or anything like that. The question was very simple - is it valid JSON?

+1  A: 

If you want to use the numbers directly, you shouldn't put them in quotes. It is valid JSON, but chances are that what you want to do is:

{"something":1,"mode":"true","number":1234}

You need to add more information if you want better answers.

EDIT: Eh... and yes, the boolean shouldn't be quoted either, unless you want to convert it yourself, for some reason.

Felixyz
+7  A: 

It is, but you've got both the boolean (mode) and numeric (number) elements as strings. Shouldn't it be:

{"something":"1","mode":true,"number":1234}
Daniel Roseman
Thanks, will look into this.
mtc06
+4  A: 

It is valid JSON if all values of the dictionary are Strings. This is also valid JSON:

{"something": 1, "mode": true, "number": 1234}

Usually, however, a 406 error happens when you ask for a response type (such as html or json) and the server cannot send it in that type. Why do you think the input is invalid?

Kathy Van Stone
A: 
  • yes this is valid JSON
  • although if you're planning on outputting this as the result of a HTTP request, you'll need to escape all the quotes

$str = "{\"something\":\"1\",\"mode\":\"true\",\"number\":\"1234\"}"; echo $str

+1  A: 

I use a simple copy/paste tool called JASONLint ( http://www.jsonlint.com/ ) to test my mountains of JSON. You may dig it.

neuman