1
I’m trying to generate a file Json
from a SELECT
of the SQL SERVER 2016 table. There are about 4713 rows, this is exceeds the value set in the property maxJsonLength
. I can exceed that set value?
Web.config
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="500000000"/>
</webServices>
</scripting>
</system.web.extensions>
Class Model:
public class ProcessoMobile
{
public string Natureza { get; set; }
public string Vara { get; set; }
public string Agencia { get; set; }
public string Comarca { get; set; }
public Decimal Valor { get; set; }
public string GCPJ { get; set; }
public string ParteContraria { get; set; }
public string AdvogadoContraria { get; set; }
public string Telefone { get; set; }
public DateTime DataDistribuicao { get; set; }
public string Carteira { get; set; }
public string Contrato { get; set; }
public string CidadeAgencia { get; set; }
public string ProcessoID { get; set; }
public bool PesquisaBens { get; set; }
public bool Ativo { get; set; }
public bool Arquivado { get; set; }
public bool Irrecuperavel { get; set; }
public bool Encerrado { get; set; }
public string CarteiraAtual { get; set; }
public string ContratoAtual { get; set; }
public string CpfCnpj { get; set; }
public string Conta { get; set; }
public string NomeAdvogado { get; set; }
}
Function:
public static void CriaJson()
{
List<ProcessoMobile> processList = new List<ProcessoMobile>();
using (SqlConnection con = new SqlConnection(MyConnectionString))
{
using (SqlCommand command = new SqlCommand("select_Processo_Mobile", con))
{
command.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
ProcessoMobile p = new ProcessoMobile()
{
Natureza = reader["Natureza"] ==
DBNull.Value ? string.Empty :
Convert.ToString(reader["Natureza"]),
Vara = reader["Vara"] ==
DBNull.Value ? string.Empty :
Convert.ToString(reader["Vara"]),
Agencia = reader["Agencia"] ==
DBNull.Value ? string.Empty :
Convert.ToString(reader["Agencia"]),
Comarca = reader["Comarca"] ==
DBNull.Value ? string.Empty :
Convert.ToString(reader["Comarca"]),
Valor = reader["Valor"] ==
DBNull.Value ? decimal.MinValue :
Convert.ToDecimal(reader["Valor"]),
GCPJ = reader["GCPJ"] ==
DBNull.Value ? string.Empty :
Convert.ToString(reader["GCPJ"]),
ParteContraria = reader["ParteContraria"] ==
DBNull.Value ? string.Empty :
Convert.ToString(reader["ParteContraria"]),
AdvogadoContraria = reader["AdvogadoContraria"] ==
DBNull.Value ? string.Empty :
Convert.ToString(reader["AdvogadoContraria"]),
Telefone = reader["Telefone"] ==
DBNull.Value ? string.Empty :
Convert.ToString(reader["Telefone"]),
DataDistribuicao = reader["DataDistribuicao"] ==
DBNull.Value ? DateTime.MinValue :
Convert.ToDateTime(reader["DataDistribuicao"]),
Carteira = reader["Carteira"] ==
DBNull.Value ? string.Empty :
Convert.ToString(reader["Carteira"]),
Contrato = reader["Contrato"] ==
DBNull.Value ? string.Empty :
Convert.ToString(reader["Contrato"]),
CidadeAgencia = reader["CidadeAgencia"] ==
DBNull.Value ? string.Empty :
Convert.ToString(reader["CidadeAgencia"]),
ProcessoID = reader["ProcessoID"] ==
DBNull.Value ? string.Empty :
Convert.ToString(reader["ProcessoID"]),
PesquisaBens = reader["PesquisaBens"] ==
DBNull.Value ? false :
Convert.ToBoolean(reader["PesquisaBens"]),
Ativo = reader["Ativo"] ==
DBNull.Value ? false :
Convert.ToBoolean(reader["Ativo"]),
Arquivado = reader["Arquivado"] ==
DBNull.Value ? false :
Convert.ToBoolean(reader["Arquivado"]),
Irrecuperavel = reader["Irrecuperavel"] ==
DBNull.Value ? false :
Convert.ToBoolean(reader["Irrecuperavel"]),
Encerrado = reader["Encerrado"] ==
DBNull.Value ? false :
Convert.ToBoolean(reader["Encerrado"]),
CarteiraAtual = reader["CarteiraAtual"] ==
DBNull.Value ? string.Empty :
Convert.ToString(reader["CarteiraAtual"]),
ContratoAtual = reader["ContratoAtual"] ==
DBNull.Value ? string.Empty :
Convert.ToString(reader["ContratoAtual"]),
CpfCnpj = reader["CpfCnpj"] ==
DBNull.Value ? string.Empty :
Convert.ToString(reader["CpfCnpj"]),
Conta = reader["Conta"] ==
DBNull.Value ? string.Empty :
Convert.ToString(reader["Conta"]),
NomeAdvogado = reader["NomeAdvogado"] ==
DBNull.Value ? string.Empty :
Convert.ToString(reader["NomeAdvogado"]),
};
processList.Add(p);
}
reader.Close();
reader.Dispose();
con.Close();
con.Dispose();
command.Dispose();
var jsonSerialiser = new System.Web.Script.Serialization.JavaScriptSerializer();
string jsonString = jsonSerialiser.Serialize(processList);
System.IO.File.WriteAllText(@"D:\processList.json", jsonString);
}
}
}