1

I have trouble using Regex to split a text file of JSON objects into string. The array of JSON objects are downloaded from an url and is meant to be processed by some javascript function. But I want to read them in C#. I have downloaded the file and just need to split it into individual JSON objects. The format of the text file is:

{......},{"S":...}

So I want to split it into a string[] so each JSON object is a string:

{"S":...}
{"S":...}
{"S":...}
{"S":...}

I want to leave out the comma that separates them in the original text file.

string[] jsons = Regext.Split(txtfile, "\{\"S\":");

But this doesn't work. How can I split it correctly?

Kasper Hansen
  • 6,007
  • 20
  • 67
  • 101
  • http://stackoverflow.com/questions/13605667/c-sharp-json-parsing or http://stackoverflow.com/questions/6620165/how-to-parse-json-in-c may help u – internals-in Oct 27 '13 at 17:31

2 Answers2

1

You can use the JsonTextReader class provided by the Newtonsoft.JSON assembly (acquirable through NuGet).

Konstantin Dinev
  • 32,797
  • 13
  • 71
  • 95
1

If you aren't aware already this is a great tool http://regexr.com?36u96

Try

string[] splits = Regex.Split(txtfile, @"(?<=\}),");
Dharun
  • 593
  • 7
  • 25
  • It won't work if there's all sorts of characters in between, it's a starting point and works with his example. Can easily add \s* or .* to catch other characters. – Dharun Oct 27 '13 at 19:29