0

In short, I need a JToken.Parse(string) that don't create new instance of JToken, but instead modifies already existing one.

My specific task requires that I don't use Jtoken.Parse(string), which is creating new instance of JToken, but instead forces me to use already existing instance of JToken that I have to populate with some data.
Initially JToken existingInstance is an empty JToken and I have a json string that has data I need to put into existingInstance.
Sorry, but I can't find any approaches here.
I tried to recursively copy one from another, but Add only supported in JObject
There are many questions about populating already existing object of some type, but I can't find anything about populating already existing JToken.

Example JSON file I use:

{
  "type": "stated",
  "width": 32,
  "height": 32,
  "speed": 0.1,
  "states": [
    {
      "x": 0,
      "y": 0,
      "count": 4,
    },{
      "x": 0,
      "y": 32,
      "count": 4
    }
  ]
}
  • 1
    You could load the string to a new `JContainer` then merge it onto the existing `JContainer`. See [Merge two JTokens into one](http://stackoverflow.com/q/37756656/3744182). Note this only works for containers (`JObject` and `JArray`). The primitive `JValue` cannot be merged. – dbc Jan 18 '17 at 01:46
  • @dbc, Thanks! Looking good! I'll post it as an answer, if you don't mind? – user3209757 Jan 18 '17 at 12:36
  • Sure, go ahead. – dbc Jan 18 '17 at 19:35

0 Answers0