In my c# class I have the following class:
public class Product
{
public int product_id;
public int quantity;
public string book_cost;
}
If I serialize it with JavaScriptSerializer
then I get back
{"product_id":0,"quantity":0,"book_cost":"hello"}
after setting the values.
Thats c#, but how could I serialize a javascript function to match this?
I am wanting to parse a js function into a c# class
Example.... if I had a class in c# and I wanted to send it to some other webserver, I could serialize the object and make it into JSON using
var serializer = new JavaScriptSerializer();
serializer.Serialize(new Product());
public class Product
{
public int product_id = 0;
public int quantity = 0;
public string book_cost = "hello";
}
then on the other side i could have this:
var serializer = new JavaScriptSerializer();
Product p = serializer.Deserialize<Product>(products);
Console.WriteLine(p.product_id);
public class Product
{
public int product_id;
public int quantity;
public string book_cost;
}
and it would print out 0 because I created a new product class with those values from the other class, however I want one side to be js (the sending side) and the other to be c# (the receiving side)
here is more of an example:
js side...
I have this function, I have set the values to this, but I would change them at runtime.
function Product(){
this.product_id = 0;
this.quantity = 0;
this.book_cost = "hello";
}
then I would want to generate from this I would want to generate
{"product_id":0,"quantity":0,"book_cost":"hello"}
Then on the other side I would want to populate the Product class that is above. I am only going to be using strings, integers, and date objects. If I serialize a DateTime object in c# it comes out to be
{"date":"\/Date(-62135596800000)\/"}