1

I have a string in the form of "{value: "some"}" (Obtained by serializing object but without quotes on the property name) OR "{"value": "some"}"

I wish to convert it a object (Similar to new {value = "some"}) And not JObject {"value" = "some"}

Any help?

Mohit Jain
  • 135
  • 1
  • 4
  • 12
  • Perhaps a duplicate of .... http://stackoverflow.com/questions/13652983/dynamic-jcontainer-json-net-iterate-over-properties-at-runtime – Mick Oct 09 '15 at 06:03

1 Answers1

3

Check here for info on deserializing anonymous types using Json.NET.

var definition = new { Name = "" };
string json1 = @"{'Name':'James'}";
var customer1 = JsonConvert.DeserializeAnonymousType(json1, definition);

Console.WriteLine(customer1.Name);
// James

string json2 = @"{'Name':'Mike'}";
var customer2 = JsonConvert.DeserializeAnonymousType(json2, definition);

Console.WriteLine(customer2.Name);
// Mike
Joe
  • 70
  • 8