Issues parsing a 1GB json file using JSON.NET

前端 未结 2 637
闹比i
闹比i 2021-01-28 02:29

I have gotten an application where the input has been scaled up from 50K location records to 1.1 Million location records. This has caused serious issues as the entire file was

2条回答
  •  野的像风
    2021-01-28 03:04

    Thanks for all the help, I've managed to get it doing what I want which is de-serializing individual location objects.

    If the item is converted to a JObject it will read in the full object and de-serialize it, this can be looped to get the solution.

    This is the code that was settled on

    while (reader.Read())
    {
        if (reader.TokenType == JsonToken.StartObject && reader.Depth == 2)
        {
            location = JObject.Load(reader).ToObject();
    
            var lv = new LocationValidator(location, FootprintInfo.OperatorId, FootprintInfo.RoamingGroups, true);
            var vr = lv.IsValid();
            if (vr.Successful)
            {
                yield return location;
            }
            else
            {
                errors.Add(new Error(elNumber, location.LocationId, vr.Error.Field, vr.Error.Detail));
                if (errors.Count >= maxErrors)
                {
                    yield break;
                }
            }
    
            ++elNumber;
        }
    }
    

提交回复
热议问题