问题
I am working with a third-party system that provides audio files and various pieces of data about the audio files. The problem I am dealing with is that the pieces of data are JSON objects, that are sprinkled essentially randomly throughout the binary data of the audio file.
No information is provided for where the JSON is and the binary data is.
So, one way to deal with this is to simply go through the file, and every time I encounter {
, I try to parse out a json object from that point. If I succeed, I'd store the parsed object and continue on, otherwise I consider the {
binary data and add it to the audio queue.
I usually use JSON.Net for my JSON stuff. If I use a JsonTextReader
on my input stream, I can parse from my position in the array and get what I need. I would then start reading again from the byte after the closing }
However, JsonTextReader
will read in large chunks at a time. So when I check my position of the underlying stream, its position is well beyond the closing }
. JsonTextReader
doesn't have any properties regarding its position, apart from a Line and Char property, which would be a hassle to use. However, there is a private member _charPos
which would provide me exactly what I want.
Is there an alternative way to get at that info, without modifying the library, without computing line numbers myself, or resorting to using reflection to get at the private member?
来源:https://stackoverflow.com/questions/53108483/how-to-get-detailed-position-information-from-jsontextreader