rajkumar
rajkumar

Reputation: 7

Getting error when parsing JSON string which includes double quotes

I am trying to sent username as raj"gogetter"mclean using JSON but getting below error:

{"$errorDump":"org.codehaus.jackson.JsonParseException:Unexpected character ('g' (code 103)):was expecting comma to separate OBJECT entries\n at     [Source: com.softwareag.is.enterprisegateway.net.HttpInputStream@3b2827cd;

I am using string format like below:

Utility.GetGlobalSSOWebMethod("POST", uri, ref statusCode, @"{""username"": """ + userName + @""",""password"":""" + password + @""",""country"":""" + this.CountryCode + @""",""redirect"":""" + redirectApplicationUrl + @"""}");          

This is the json object which is causing an error:

json object

I tried looking to few questions posted here but not the exact issue happened.Also please suggest how to use Json serializer instead of string concatenations.

Upvotes: 0

Views: 842

Answers (1)

Vardhan Dugar
Vardhan Dugar

Reputation: 31

You might need to escape quotes (\" instead of ") if you are embedding a string in a JSON string. An example could be that you are trying to embed some HTML into a JSON string, and this HTML contains quotes and all these fabulous things which break the serialization.

Upvotes: 1

Related Questions