Hi can anybody help me out from this.
I have an HTML page. This page contains Textboxes for FirstName,MiddleName, LastName, etc.
On button clcik of this HTML page i am calling a javascript function. Here i am getting all the HTML page contaols and its value using JQuery Serialization. Then passing this values to my WCF service hosted in server.
This service will parse this string into corresponding objects and save the values into the database.
So In HTMl page i written the Javascript function like below:
pmamml.ButtonClick = function() {
var formData = $("#form1").serializeArray();
var stringJson;
$.getJSON('ajax/test.json', function(formData) {
stringJson= JSON.stringify(formData)
});
//alert(stringJson);
$.ajax({
type: 'GET',
url: 'http://URL/Service.svc/Update?formData=' + JSON.stringify(formData),
error: pmamml.ajaxError,
success: function(msg) {
document.write(msg);
//alert(msg);
},
});},
And in WCF service i written:
[WebInvoke(Method = "GET", UriTemplate = "/Update?formData={formData}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public string Update(string formData)
{
// Here i am receiving formdata string as
// formData = "[{\"name\":\"FirstName\",\"value\":\"Pankaj\"},{\"name\":\"MiddleName\",\"value\":\" \"},{\"name\":\"LastName\",\"value\":\"KUMAR\"}]";
}
I wanna deserialize this string into List object or keyvaluepair or Dictionary any one of the above format.
So that i can save this value into database.
How can we do this. Thanks in advance.
yup i got the solution
This is my updated JQuery
}
In above method formData will pass the JSON string like below:
{ “FirstName”:”Raja”,”MiddleName”:”Raja”,”LastName”:”Kumar”}.
And in my WCF Service, converted this JSON string to Object.
This is working fine.
Thnak you all for your kind response.. 🙂