My JSON goes into my program as follows:
{
"Foo": "some string",
"Bar": { "Quux" : 23 }
}
How can I use JavaScriptSerializerfor parsing , but treat the value of Bar as a string instead of a sub-object? The code below throws an exception, as expected.
After deserializing, I want to thing.Barcontain a string { "Quux" : 23 }. Is there an easy way to do this?
class Thing
{
public string Foo { get; set; }
public string Bar { get; set; }
}
class Program
{
static void Main(string[] args)
{
string json = "{ \"Foo\": \"some string\", \"Bar\": { \"Quux\": 23 }}";
var serializer = new JavaScriptSerializer();
var thing = serializer.Deserialize<Thing>(json);
}
}
source
share