1

I need to deserialize custom JSON to anonymous C# object.

My sample JSON (can be any, even with nested properties as objects):

var json = "{ 'Surname': 'Wick'}"; 

And I want to be deserialized as:

var jsonResult = new { Surname = "Wick" };

But I end up with something like this:

enter image description here

11
  • 1
    See this for Newtonsoft Json Commented Apr 16, 2017 at 12:44
  • 1
    The generic type you pass should be dynamic and not object Commented Apr 16, 2017 at 12:54
  • 1
    test the two but do jsonResult.Surname in the watch Commented Apr 16, 2017 at 13:09
  • 1
    I know :) that is why access the property jsonResult.Surname - with the object you'll get an exception, with dynamic you'll get the value. In both cases you get a dynamic object but in the object case it is cased to object... Also you can have a look under the Dynamic View line:) Commented Apr 16, 2017 at 13:14
  • 1
    then use Json.Decode... different frameworks, each with its own implementation Commented Apr 16, 2017 at 13:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.