2

im tyring to deserialize my object coming from client side having following format:

{'goalplans':
   [{"goalPlan":0,"accountId":11,"objectiveId":17,"activity":35,"acctOwner":0,"planDay":"1/30/2013","spend_budget":12,"sortBy":0,"activityFlag":0},
    {"goalPlan":0,"accountId":11,"objectiveId":17,"activity":35,"acctOwner":0,"planDay":"1/30/2013","spend_budget":12,"sortBy":0,"activityFlag":0},
    {"goalPlan":0,"accountId":11,"objectiveId":17,"activity":35,"acctOwner":0,"planDay":"1/30/2013","spend_budget":12,"sortBy":0,"activityFlag":0},
    {"goalPlan":0,"accountId":11,"objectiveId":17,"activity":35,"acctOwner":0,"planDay":"1/30/2013","spend_budget":12,"sortBy":0,"activityFlag":0},
    {"goalPlan":0,"accountId":11,"objectiveId":17,"activity":35,"acctOwner":0,"planDay":"1/30/2013","spend_budget":12,"sortBy":0,"activityFlag":0},
    {"goalPlan":0,"accountId":11,"objectiveId":17,"activity":35,"acctOwner":0,"planDay":"1/30/2013","spend_budget":12,"sortBy":0,"activityFlag":0}
]}

thing is that im not able to deserialze it on my server side .

Please tell me how can i deserialize the Json object to a list object like List . i tried many ways but not working.

3 Answers 3

4

serialize/deserialize objects to/from JSON exist Since .NET 3.5, try this

using System.Web.Script.Serialization;

var jss = new JavaScriptSerializer();
var dict = jss.Deserialize<dynamic>(jsonText);

See here for more details

Hope this helps

Sign up to request clarification or add additional context in comments.

4 Comments

Looks to me like it should be a Dictionary<string,List<Dictionary<string, string>>> (Or possibly the last string should be int, I can't remember if the JavaScriptSerializer will do ints.)
Edited, it was just for sample @Rawling, in this case we don't need dictionary at all
Mapping the JSON structure to some form of object model definitely makes life easier.
The standard serializers of the .NET framework aren't nearly as powerful as JSON.NET.
2

One possible third party component is JSON.NET. Personally I have made very good experience with that library ( it is available using nuget for example )

Comments

0

I solved the problem by myself. Simply adding [Serializable] to my class and changed method to take argument of class type ... e.g.

//My class
[Serializable]
public class GoalPlanList{}

//method
public static int GoalplanAddUPD(List<GoalPlanList> goalplans)
{
    foreach (GoalPlanList goals in goalplans)
    {}
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.