开发者

Can WCF accept JSON encoded using single quotes and non-quoted identifiers?

开发者 https://www.devze.com 2023-02-09 15:17 出处:网络
Is there a way that I can instruct WCF开发者_如何学C to accept JSON that is formatted using either single quotes (as opposed to double quotes):

Is there a way that I can instruct WCF开发者_如何学C to accept JSON that is formatted using either single quotes (as opposed to double quotes):

{
   'foo': 'bar'
}

Or using non-quoted identifiers like so:

{
    foo: 'bar'
}

As it is, it seems like JSON will only be accepted if it is formatted like so:

{
    "foo": "bar"
}

Using either of the first two example results in a 400 (bad request).


The first two examples are invalid JSON texts. http://www.ietf.org/rfc/rfc4627.txt

object = begin-object [ member *( value-separator member ) ]
end-object

member = string name-separator value

string = quotation-mark *char quotation-mark

quotation-mark = %x22      ; "


DataContractJsonSerializer always writes strict JSON.

At various points during deserialization (generally missing end tags for arrays or objects, or improper escaping, or improperly formatted numbers), it will accept incorrect, non-strict JSON.

However, I can tell you definitively that this is not one of those cases. DataContractJsonSerializer always requires double-quoted strings for JSON.

Hope this helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号