Created
June 27, 2013 01:50
-
-
Save hugozap/5873370 to your computer and use it in GitHub Desktop.
Read a big json file in c#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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