Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm New to Umbraco and I want to create Web Api. So I need help how to serialize IPublishedContent in JSON.
With Newtonsoft.Json you can:
But i have done this in the past and it often crashes as the IPublishedContent object is so large, i would advise mapping the IPublishedContent item to a custom model manually or using models builder, and then serialise that model instead.
Best to use the UmbracoApiController class to manage a transformation of IPublishedContent as the object is too complex for JSON deserialization. You can map it to a less complex object and expose it through the controller. The controller already has access to the Umbraco Helper class which will allow you to do things link query IPC.
Look at the documentation here:
As the others say, out-the-box, serializing IPublishedContent object will throw various errors. The only way to do it is with a custom resolver for JSON.NET.
See this thread for the code...
Then you should be able to do something like this...
var settings = new JsonSerializerSettings
ContractResolver = new PublishedContentContractResolver()
var serialized = JsonConvert.SerializeObject(l, Formatting.Indented, settings);
Hope this helps.
Thank you very much for your answers, they were really helpful.
You all have a nice day ,
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted