Skip to content

Instantly share code, notes, and snippets.

@hugozap
Created June 27, 2013 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugozap/5873370 to your computer and use it in GitHub Desktop.
Save hugozap/5873370 to your computer and use it in GitHub Desktop.
Read a big json file in c#
using (var strreader = new StreamReader(filepath))
{
using (var reader = new JsonTextReader(strreader))
{
while (reader.Read())
{
if (reader.TokenType == JsonToken.StartObject)
{
var account = JObject.Load(reader);
//GYJ tiene atributo type que puede ser Cliente o Sucursal
var accountType = account.GetValue("Type");
if (accountType != null && accountType.HasValues)
{
if (accountType.Value<string>() == "Cliente")
{
Console.WriteLine("Procesando cliente");
packet.Add(account);
processedRecords++;
//Enviar rafagas de tama;o (packetSize)
if (packet.Count >= packetSize)
{
SendAccountPacket(packet);
packet.Clear();
}
}
else if (accountType.Value<string>() == "Sucursal")
{
Console.WriteLine("Procesando sucursal (TODO)");
//TODO: Cargar sucursales
}
}
else
{
//Si no hay valor se toma como cuenta
//Para otras implementaciones que no sean GYJ
Console.WriteLine("Procesando cliente");
packet.Add(account);
processedRecords++;
//Enviar rafagas de tama;o (packetSize)
if (packet.Count >= packetSize)
{
SendAccountPacket(packet);
packet.Clear();
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment