mercredi 19 août 2015

Parse JSON output in asp.net MVC 3

I want to parse JSON string in C# asp.net mVC3 but not getting idea of how to parse my json string. my JSON String is like that:

{"dept":"HR","data":[{"height":5.5,"weight":55.5},{"height":5.4,"weight":59.5},{"height":5.3,"weight":67.7},{"height":5.1,"weight":45.5}]}

Code:

var allData = { dept: deptname, data: arr};
var allDataJson = JSON.stringify(allData);
$.ajax({
                url: '<%=Url.Action("funx","Controller")%>',
                data: { DJson: allDataJson },
                async: false,
                cache: false,
                type: 'POST',
                success: function (data) {
                    alert("success data: "+data);
                }

}); 

public String funx(string DJson)
{
     System.Diagnostics.Debug.WriteLine("Returned Json String:" + DJson);

     // var yourObject = new JavaScriptSerializer().Deserialize(DJson);
     return "successfull";
}

I am new to asp.net. I want to parse the string and save it in database.

Aucun commentaire:

Enregistrer un commentaire