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?

1

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you but it requires me know the properties of the object (which is unknown and varies)
@MohitJain you've not specified this requirement in your question

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.