tags:

views:

27

answers:

1

How do I safely add a variable to JSON data with C#? For instance I might have [{"data": "data"}, {"data": "data"}] or I might have {"data": "data"}. How do I add a new variable "newdata": "newdata" to the structure?

+1  A: 

If you have the availability of the .Net 3.5SP1 framework, have a look at the JSONReaderWriterFactory class. It makes a XmlDictionaryReader/Writer for use with JSON.

You can use a reader/writer combination to read what's there, write what was there and add your own entries.

Hope this helps,

Marvin Smit
Won't be able to test it until Monday, but I think you are on the right track here.
HeavyWave