hello expert, i have build a WCF rest api with c# 3.5, here is my sample code public string Login(Login objLogin) { string strResult = ""; if (objLogin.UserName == "username" && objLogin.Password == "password") { StringBuilder sb = new StringBuilder(); StringWriter
sw = new StringWriter(sb); using (JsonWriter jsonWriter = new JsonTextWriter(sw)) { jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("Status"); jsonWriter.WriteValue("Success"); jsonWriter.WritePropertyName("Message"); jsonWriter.WriteValue("Login
Successfully"); jsonWriter.WriteEndObject(); } return sb.ToString(); } } after execute this code i am getting the json response in Fiddler with this format: {"LoginResult":"{\"Status\":\"Success\",\"Message\":\"Login Successfully\"}"} cant i get the response
with given below format {"LoginResult":"{"Status":"Success","Message":"Login Successfully"}"} i tried much but the json is by default taking "\" , I want the json response with ":" only without "\". Thanks in advance
Actually the "\" is the escape character that allow us to use special resreved characters inside string .You are getting json with "\" these symbols so that compiler can add " character in the string otherwise it represent start of a new string or end of
a string .So when you manipulate this string and perform any functions on it whether using java script or jquery or C# these character will not be accountable and will not create problems.
So they will cause no any problem you can consider them as invisible.
Hello Ranjeet, Thanks for your reply. my rest api json response is using for iPhone application and in objective C it's not acceptable. an only the format of ":" is working. So if posible then can you please give me a sample code of wcf rest api with jquery
with this format of ":" Thanks in advance
mamta deshmu...
Member
12 Points
13 Posts
Issue with JSON response format with WCF c# 3.5
Nov 24, 2011 01:15 PM|LINK
RanjeetAulak...
Participant
1042 Points
186 Posts
Re: Issue with JSON response format with WCF c# 3.5
Nov 24, 2011 06:01 PM|LINK
Hi
Actually the "\" is the escape character that allow us to use special resreved characters inside string .You are getting json with "\" these symbols so that compiler can add " character in the string otherwise it represent start of a new string or end of a string .So when you manipulate this string and perform any functions on it whether using java script or jquery or C# these character will not be accountable and will not create problems.
So they will cause no any problem you can consider them as invisible.
Regards.
Blog-http://www.aspbits.com
mamta deshmu...
Member
12 Points
13 Posts
Re: Issue with JSON response format with WCF c# 3.5
Nov 25, 2011 01:33 PM|LINK