0

I am making a game in Unity C# where request is made to external server every 10 seconds about the player's playing state. The server responses with newline-delimited JSON, for example.

{"gamestate":"play","score":120,"compare":"ascending","compitPosition":"5/13"}
{"gamestate":"play","score":80,"compare":"descending","compitPosition":"9/13"}
{"gamestate":"pause","score":70,"compare":"descending","compitPosition":"8/13"}

Is there a way to parse such newline-delimited json so that I can get individual data or convert it to proper JSON format to parse and get the data ?

user3303274
  • 729
  • 2
  • 8
  • 21
  • Generate your structure from json [here](http://json2csharp.com/) then use what's in the duplicate to de-serialize your json. – Programmer Apr 17 '18 at 10:18
  • the question is marked duplicate for serialize/Deserialize JSON. But this question is about newline delimited json. Please have a look before marking it deplicate – user3303274 Apr 17 '18 at 10:23
  • I saw that. Use json array. That's the proper way to retrieve multiple json data. I changed the duplicate link since that's what you want to go with. – Programmer Apr 17 '18 at 10:26
  • @user3303274 there's no "newline-delimited json". There's an attempt at domain squatting with that name. Writing a *document* per line is used to *stream* a large number of items, eg for big data or event processing scenarios. Instead of trying to read all text at once you should read it one line at a time and parse that line only. This way you can start returning results immediatelly using a minimal amount of memory even for GBs of text. – Panagiotis Kanavos Jul 16 '18 at 10:17
  • @user3303274 Imagine trying to parse a single 500MB full of JSON documents otherwise. It would take a lot of time just to load the text, use a *lot* of memory on top of that to parse it and a lot of memory to generate *all* results. You wouldn't be able to process anything until everything was parsed. – Panagiotis Kanavos Jul 16 '18 at 10:19

0 Answers0