How do I safely add a variable to JSON data with C#? For instance I might have 开发者_如何学Python[{"data": "data"}, {"data": "data"}]
or I might have {"data": "data"}
. How do I add a new variable "newdata": "newdata"
to the structure?
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,
精彩评论