开发者

Json.NET deserializing buffers with more than one object?

I need to talk to a service that sends a continuous stream of JSON objects with nothing in between. I'm looking at Json.net, but I could use some other .NET thing if it will do the job.

After I've read a sequence of bytes, I might have a partial object, in which case I want to wait until I开发者_StackOverflow中文版 get more data, or I might have one or more whole objects, possibly followed by a partial object.

Json.net throws an exception if there's more than one top-level object, or just a partial one. The data in the exception is not that useful - it gives you a line and column number. If it had an offset into the byte buffer that would be more useful, as I could just lop off that many bytes and try again.

Any ideas about how to cope with this?

Thanks


Sounds like you'll have to create something manually to break things up prior to throwing the content at Json.NET. Either that or get the sender to include some kind of terminator which indicates the end of a JSON blob. You'd have the same problem with XML, so it's not just tied to the datatype, it's tied to your implementation.

I would suggest talking to the author of the service and if possible get them to mark the end of a JSON entity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜