开发者

Using:JavascriptConverter in ASP.NET

开发者 https://www.devze.com 2023-03-10 04:56 出处:网络
I\'m currently serializing objects like this: public static string ObjToJson(List<MyObject> TheObjects){

I'm currently serializing objects like this:

public static string ObjToJson(List<MyObject> TheObjects){

  JavascriptSerializer TheSerializer = new JavascriptSerializer();
  TheSerializer.RegisterConverters( new JavascriptConverter [] { new ObjectToJson() });
  string JsonObj = TheSerializer.Serialize(TheObjects);
  return JsonObj; }
开发者_Python百科

And then I have this:

public class TheObjToJson : JavascriptConverter{
 public override IDictionary<string,object> Serialize (object obj, JavascriptSerializer serializer)
    {
    ...
     return jsonstring;
    }
}

Is this the fastest/best way to do JSON in ASP.NET?


I think the most popular JSON library is json.net. It's fast and easy to use.

0

精彩评论

暂无评论...
验证码 换一张
取 消