private void createJson() { InmueblesBLL bllinmuebles = new InmueblesBLL(); dt = bllinmuebles.SelectSharedJson(); string json; string data = ""; int position = 0; int count = 0; foreach (DataRow dtRow in dt.Rows) { count++; } foreach (DataRow dtRow in dt.Rows) { position++; data += "{" + "\"Fecha\"" + ":" + "\"" + dtRow["Fecha"].ToString().Trim() + "\"" + "," + "\"Inmobiliaria1\"" + ":" + "\"" + dtRow["Inmobiliaria1"].ToString().Trim() + "\"" + "," + "\"Inmobiliaria2\"" + ":" + "\"" + dtRow["Inmobiliaria2"].ToString().Trim() + "\"" + "," + "\"TiposDeInmuebles\"" + ":" + "\"" + dtRow["Tipo de Inmueble"].ToString().Trim() + "\"" + "," + "\"Direccion\"" + ":" + "\"" + dtRow["Direccion"].ToString().Trim() + "\"" + "," + "\"Localidad\"" + ":" + "\"" + dtRow["Localidad"].ToString().Trim() + "\"" + "," + "\"Operacion\"" + ":" + "\"" + dtRow["Operacion"].ToString().Trim() + "\"" + "," + "\"Zona\"" + ":" + "\"" + dtRow["Zona"].ToString().Trim() + "\"" + "}"; if (position < count) { data +=","; } } json = "{\"count\":" + count + ",\"inmueblesShared\":[" + data; json += "]}"; Response.Clear(); Response.ContentType = "application/json; charset=utf-8"; Response.Write(json); Response.End(); }