Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a class
[DataContract]
public class testing
{
[DataMember(EmitDefaultValue = false)]
public string test1{ get; set; }
[DataMember(EmitDefaultValue = false)]
public string testA{ get; set; }
[DataMember(EmitDefaultValue = false)]
public string testB{ get; set; }
}

and i have an interface
[OperationContract]
[FaultContract(typeof(CustomException))]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "SaveAliasOfEndPoints")]
bool Mymethod(testing objtesting);


and i have implementation like this
public bool Mymethod(testing objtesting)
{
return true;
}

{
"test1 ":"XXX",
"testA":"XXX",
"testB":"XXX"
}

now the problem is here
when i post json with parameter "test1 " it have space at the end
now json is parsed to my class testing in code with test1 have value null
which is wrong. i want to catch this space and throw user defined error.

please help me in this
thanks in advance
Posted

1 solution

White spaces in the json standard are ignored unless they are in quotes (the string part).

"test1" and "test1 " are two different things for the json parser, and the second will not be generated by json serializer from the class definition you have given.
 
Share this answer
 
Comments
sharmarun 6-Oct-14 2:33am    
Yes, you are right,
then
{
"test1 ":"XXX",
"testA":"XXX",
"testB":"XXX"
}
must be wrong and wcf service not able to call the Mymethod with this json
but it is able to call and hit the method.
Mehdi Gholam 6-Oct-14 3:04am    
The json deserializer will do its best and give you a "testing" object with as much information set (the rest will be default values or null).
sharmarun 6-Oct-14 3:10am    
thanks Mehdi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900