Closed Alphadan28 closed 2 years ago
Is it possible that the key does not exist? For non-optimal performance, try:
if (d.HasMember(key) && d[key].IsDouble())
thanks will try it .
This checks if the key exist before trying to get the value right?.
I thought about doing this but i was trying a more efficient solution like handling the exception since is a race condition.
The key should be there always the thing is that when i read the file the other program might be writing it in that exact moment and may be, there is a small chance to read the json incomplete in most of the cases the if(!d.HasParseError()){ would ignore it and try to read it 5s after.
Im using a raspberry pi so my resources are limited is there any way to just handle the exception avoiding it to crash instead of make an additional search for each key? the json is quite big around 580kb.
your solution seems to work is about 24 hours running without crashing.
crashed again :(
The library is working perfectly I forgot to report here, the issue was never rapidjson,
My project opens a file periodically, which is created by another process and sometimes the file was open before the other process completed the saving of the file so the error came when opening partial JSON.
The solution was to just ensure that the file was completed before trying to parse.
So far this project is running continuously for more than a year and has not crashed even a single time.
you can close this as i got the solution and THANKS for such amazing library.
im getting this exeption:
BotSupp: rapidjson/document.h:1218: rapidjson::GenericValue<Encoding, Allocator>& rapidjson::GenericValue<Encoding, Allocator>::operator[](const rapidjson::GenericValue<Encoding, SourceAllocator>&) [with SourceAllocator = rapidjson::MemoryPoolAllocator; Encoding = rapidjson::UTF8<>; Allocator = rapidjson::MemoryPoolAllocator]: Assertion `false' failed.
im building a bot which processes the json produced by another program and depending on those values it will send me alerts to telegram.
the problem happens once a day or so, so is a race condition, i guessing its caused by opening a incomplete json but some how not producing parse error.
Tried to enclose the code with a try catch but still crashes.
this is the code: