How to get detailed position information from JsonTextReader

天涯浪子 提交于 2019-12-12 18:32:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!