Get Raw json string in Newtonsoft.Json Library
.net, json, json.net
Solution
You don't need to write any converters, just use the `JRaw` type as follows:
public class SomeData
{
[JsonProperty("object")]
public JRaw SomeObject { get; set;}
[JsonProperty("dsct")]
public JRaw SomeDesct { get; set; }
}
Then you can access the raw value by checking the `.Value` property:
var rawJsonDesct = (string)data.SomeDesct.Value;
If you want to retain the `string` signature, just serialize the JSON to a hidden property and have the string conversion in the accessor call instead.
Problem
I have json like this ``` { "name": "somenameofevent", "type": "event", "data": { "object": { "age": "18", "petName": "18" }, "desct": { } } } ``` and I have 2 objects like this ``` public class CustEvent { [JsonProperty("name")] public string Name { get; set; } [JsonProperty("type")] public string EventType{ get; set; } [JsonProperty("data")] public SomeData Data{ get; set; } } public class SomeData { [JsonProperty("object")] public String SomeObject { get; set;} [JsonProperty("dsct")] public String SomeDesct { get; set; } } ``` I use to parse json to object Newtonsoft.NET library. And how i can get RAW JSON into SomeObject , SomeDesct properties ? In JSON "data.object ..." are complex object and i want to get only RAW JSON String to those properties. Can you help me ?