Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,


I am passsing requeset from json to wcf service all the parameter value i get except scoredata parameter value which is dynamic. pls help me to solve my problem.

Json Request


{"ProspectNo":"1000000073","MakerId":"C136771","MkrDate":"2015/11/26","TranID":null,"ScoreData":{"Client Experience":"1","Stability & Ownership":"7","Property ownership":"22","Co-app/Guarantor":"16","proposed cost":"1800000"}}

C#
public class Score
{

    [DataMember()]
    public string ProspectNo;

    [DataMember()]
    public string MakerId;

    [DataMember()]
    public string MkrDate;

  
    [DataMember()]
    public string TranID;

    [DataMember()]
   public Dictionary<string, string> ScoreData;
}




C#


MakerId = "C136771"
MkrDate = "2015/11/26"
ProspectNo = "1000000073"
ScoreData = Count = 0
Posted

1 solution

That's because the JSON (de)serializer is looking for an array and is getting an object.

You can solve this in one of two ways; the first (and easiest) is to change the type of ScoreData to more appropriately reflect the incoming data:

C#
[DataMember()]
   public object ScoreData;


You can then use "as dynamic" when you need to read from it.

The other route would be to correct the JSON that is coming into the service. The corrected JSON would look like:
JavaScript
{"ProspectNo":"1000000073","MakerId":"C136771","MkrDate":"2015/11/26","TranID":null,"ScoreData":[{ "Key": "Client Experience", "Value": "1"},{ "Key": "Stability & Ownership", "Value" ,"7"},{"Key": "Property ownership", "Value": "22"},{"Key": "Co-app/Guarantor", "Value":"16"},{ "Key": "proposed cost", "Value":"1800000"}]}
 
Share this answer
 
Comments
Manohar Khillare 17-Dec-15 1:02am    
Thanks Nathan Minie for Response can you tell me how to implement first method i.e object datatype.
Nathan Minier 17-Dec-15 7:03am    
That depends on what you need to do. Are you trying to access specific properties in your methods, or are you enumerating them?

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