5

I am trying to set a value for a jtoken I am retreiving from the below json

{
  "Customer":
    {
      "Id": "100",
      "Country": "BE",
      "CustomerName": "Domo",
      "CustomerStatus": "Gold",
      "CreationDate": {
         "Time":""
      }
    }
 }

I am managing to retrieve the token for time using the following jPath:

Customer.CreationDate.Time

But getting a null value when trying to set the property:

 var property = timeJToken as JProperty;
 property.Value = value; 
dbc
  • 104,963
  • 20
  • 228
  • 340
TheFreeman
  • 161
  • 4
  • 13
  • 3
    If you're accessing `Customer.CreationDate.Time` via `SelectToken()`, then be aware that `SelectToken` returns the `JValue` itself, not the `JProperty`. Thus you need to replace the value using `JToken.Replace(JToken replacement) `. See [Replace part of a JSON with other (using a string token)](https://stackoverflow.com/q/33045235/3744182) for which this might be a duplicate. – dbc Jun 11 '18 at 09:25
  • But if not a duplicate, can you please share the code for a [mcve] that demonstrates how you parse your JSON and access the `timeJToken` token? – dbc Jun 11 '18 at 17:51
  • @dbc Understood, and it worked! – TheFreeman Jun 14 '18 at 11:50

0 Answers0