Ross Bush
Ross Bush

Reputation: 15175

Deserialize a Json complex property into a string of Json

Is it possible to de-serialize a complex json object as a string. I am having trouble solving an issue similar to what is described below:

public class Model
{
    public List<int> MyList { get; set; }
    public int MyInt { get; set; }
    public string MyString { get; set; }
    public string/object/variant MyProblem { get; set; }
}

Code used in the midddle-tier

model = JsonConvert.DeserializeObject<Model>(request.Model);

The problem is that MyProblem is actually a jagged array or it comes in multiple shapes by which I can't typify the structure to allow for de-serialization in a uniform manner. Is there a way that I can force JsonConvert to treat MyProblem as a string of Json instead of an object of Json?

Moment of clarity: It appears that if I define MyProblem as an object then the de-serialization will treat it as such and then MyProblem.ToString() will yield the json object as native string.

Upvotes: 0

Views: 93

Answers (1)

Ross Bush
Ross Bush

Reputation: 15175

It appears that if I define MyProblem as an object then the de-serialization will treat it as such and then MyProblem.ToString() will yield the json object as native string.

Upvotes: 1

Related Questions