js object to c 23 object

Solutions on MaxInterview for js object to c 23 object by the best coders in the world

showing results for - "js object to c 23 object"
Henri
12 Mar 2020
1// Construct a object in JS
2
3var obj = {
4  id: 0 ,
5  userName: 'Bill'
6};
7
8// C# class:
9
10public class myClass
11{
12  public int id;
13  public string userName;
14}
15
16// Then for example using AJAX send your data to C#,
17// and deserialize, when you need work with object
18
19$.ajax({
20	type: "POST",
21  	// Note that you need to pass the method as url
22	url: '<your server url>' + 'DeserializeObject',
23  	// your data is the object you want to send
24	data: obj,
25	contentType: "application/text; charset=utf-8",
26	dataType: "text"
27})
28
29[HttpPost]
30public void DeserializeObject(string objJson)
31{
32var obj = (new JavascriptSerializer()).Deserialize<myClass>(objJson);
33}
34