C# c语言javascript函数的序列化#
在我的c#类课程中,我有以下课程:C# c语言javascript函数的序列化#,c#,javascript,json,javascriptserializer,C#,Javascript,Json,Javascriptserializer,在我的c#类课程中,我有以下课程: public class Product { public int product_id; public int quantity; public string book_cost; } 如果我用JavaScriptSerializer对它进行序列化,那么我将返回 {"product_id":0,"quantity":0,"book_cost":"hello"} 设置值之后 这是c#,但是我如何序列化javascript函数来匹配它
public class Product
{
public int product_id;
public int quantity;
public string book_cost;
}
如果我用JavaScriptSerializer
对它进行序列化,那么我将返回
{"product_id":0,"quantity":0,"book_cost":"hello"}
设置值之后
这是c#,但是我如何序列化javascript函数来匹配它呢
我想把一个js函数解析成一个c#类
例如。。。。如果我在c#中有一个类,并且我想将它发送到其他Web服务器,我可以序列化该对象,并使用
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";
}
那么在另一边我可以有这个:
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;
}
然后我想从中生成我想生成的
{"product_id":0,"quantity":0,"book_cost":"hello"}
另一方面,我想填充上面的产品类。我将只使用字符串、整数和日期对象。如果我在c#中序列化DateTime对象,结果是
{"date":"\/Date(-62135596800000)\/"}
可以使用该方法序列化JSON中的对象。比如:
function Product() {
this.product_id = 0;
this.quantity = 0;
this.book_cost = "hello";
}
var p = new Product();
p.quantity = 5;
var json = JSON.stringify(p);
不要担心日期格式。任何好的序列化程序都能够识别日期的各种表示形式。应该不需要手动重新格式化任何内容。dupe:你能举个例子吗?我不知道你在问什么。@SmartLemon-我想你要的是,尽管你也可以使用WCF。两者都将在JavaScript对象和C#对象之间序列化,允许您在两个层之间处理数据。好吧,现在我更困惑了。我对您想要什么感到困惑?
function Product() {
this.product_id = 0;
this.quantity = 0;
this.book_cost = "hello";
}
var p = new Product();
p.quantity = 5;
var json = JSON.stringify(p);