I would like to place a JSON object in a service stack service and use a dynamic property in a DTO request. All the approaches I've tried so far leave the object NULL.
The javascript code I'm using is:
$.getJSON( "/api/json/reply/Hello", { Name: "Murphy", Laws: { SomeProp: "A list of my laws", SomeArr: [ { Title: "First law" }, { Title: "Second law" }, { Title: "Third law" } ] } }, function(data) { alert(data.result); } );
DTO will receive a request:
public class Hello { public string Name { get; set; } public dynamic Laws { get; set; } }
I also tried using object and JsonObject instead of dynamic in DTO.
To be complete, here is also a service:
public class HelloService : Service { public object Any(Hello request) { return new HelloResponse { Result = "Hello, " + request.Name }; } }
Murphy infiltrates the Name property without any problems, but the Laws property remains NULL.
In the end, I want to somehow iterate (using reflection?) Over the Laws property and get all the contained properties and values.
I canβt use a typed DTO here because I donβt know the JSON properties of Laws at design time (and it can change quite often).
Thanks for any help!
source share