This project has moved and is read-only. For the latest updates, please go here.

JProperty with raw JSON

Sep 26, 2008 at 2:46 PM
Edited Sep 26, 2008 at 2:47 PM

Is there a way of getting a JProperty to take raw JSON as its value or another way of achieving the same thing?  I have JSON fragments stored in a cache which at some earlier stage would have had ToString called on a root JObject.  The only way I've found of achieving this so far is to call JObject.Parse(raw) for the value part though this seems somewhat wasteful as it was valid JSON just created at another time.  My intention is to create anew JSON object to return to the caller where parts of it have been cached separately.

Kind regards


Sep 28, 2008 at 12:50 AM
I have made some changes and renamed Identifier to JsonRaw. If you make it the property type on the class you want to serialize I think it should do what you are looking for.
Sep 29, 2008 at 12:53 PM

Thanks, I must be missing something as it doesn't quite work the way I expect.  I've tried two different approaches and I get the same error about invalid state. 
The first approach I tried was passing an array of JProperty("d" + i, JValue.CreateRaw(rawJson)) to a JObject.  The 2nd approach is to use the lower level writer:


                while (loopCondition)
                    jsonWriter.WritePropertyName("d" + i);


The value of the property will essentially be some pre-existing object cached earlier.  There is no class that will contain these properties.

Kind regards