Serializing json as string property problem

Jan 2, 2009 at 2:33 PM
Hi, I'm having a trouble and cerntainly not sure if I'm doing something wrong or I've found a bug.

I have the next code

public class Something {
    public string PropertyA { get; set; }
    public string PropertyB { get; set; }
    public string JsonProperty { get; set; }

and i'm sending this json to deserialize

PropertyA : 'VirtuaGlobal.Dominio.Aplicacion.Seguridad.IUsuarioService',
PropertyB : 'Find', 
JsonProperty : {
QueryStringId: '1',
Criteria: '',
Page: 0,
PageSize: 15,
Orders: [{
Field: 'Username', Order: 0

I need JsonProperty to be serialized as string, not object, because the Json I'm sending si variable, i need to do this because i'm doing a call it 2-step deserialization where i the PropertyA and PropertyB tells me information about the type corresponding to JsonProperty to properly deserialize it.

When i'd try to deserialize this json, Json.Net thorws the next exception:


Line 606:Line 607:#if !PocketPCLine 608:       return Activator.CreateInstance(type, args);Line 609:#elseLine 610:       ConstructorInfo[] constructors = type.GetConstructors();

at Newtonsoft.Json\Utilities\ReflectionUtils.cs    Line: 608

I've debuged my aplication and found that the error throws when trying to deserialize the string property JsonProperty.

I hope you can help/guide/illuminate me  =P Jason.


Jan 3, 2009 at 11:59 AM
There isn't an option on the JsonSerializer to automatically do what you are looking for. You will need to write some custom code to get the value under JsonProperty to convert into a string.
Jan 3, 2009 at 10:31 PM
Edited Jan 3, 2009 at 10:35 PM
Hi James, 

I'd like to tell you that I have resolved my problem changing the type of JsonProperty from string to JsonRaw, now i can do a 2-step deserialization =)

Thenk you for your help James.