JSONHelper

En los ultimos proyectos he estado utilizando esta libreria para convertir datasets de SQL en JSON … la manera para llamarla es simplemente utilizar esto:

string jsonString = ;
List<sp_CountryList_Result> CountryList = ctx.sp_CountryList(language, UserId).ToList();
jsonString = CountryList.toJSON();

 

y este es el codigo de la libreria:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;
using System.Runtime.Serialization;
using System.IO;

namespace BusinessLayer.Helpers
{

public static class JSONHelper
{

public static string toJSON(this object obj)

{

JavaScriptSerializer serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue;
return serializer.Serialize(obj);

}

public static string toJSON(this object obj, int recursionDepth)
{

JavaScriptSerializer serializer = new JavaScriptSerializer();
serializer.RecursionLimit = recursionDepth;
return serializer.Serialize(obj);

}

}

}


Leave a Reply

Your email address will not be published.

Para evitar SPAM realiza la siguiente operación: *