Reputation: 9984
I have a value from a result set example [22 mm]. This is the literal value of the string and not an array. The deserialiser NewtonSoft one complains as it think its an array. How do I escape these square brackets? and deserialise it to a value [22 mm] which is the literal value
Upvotes: 2
Views: 14568
Reputation: 2509
If you serialize an object, or set the value on a JObject, the string will be escaped automatically.
However, the character [
will never need to be escaped when in a string, simply because it will always be surrounded by strings delimitors : "
.
If your Json parser thinks it's an array, it's probably because you didn't surround your value with double quotes. Add the double quotes to indicate you're dealing with strings and you should be all good.
Upvotes: 6