How do I convert rich text editor doctype properties to JSON in Umbraco 8?
I have a doctype with several properties that are rich text editors. I can grab a list of content items with this doctype with a standard query like the following:
var items = Umbraco.Content(Guid.Parse("some-guid-322342-23"))
.ChildrenOfType("doctype-alias-here")
.Where(x => x.IsVisible())
Then, I convert the items variable to JSON with the following:
var jsonSerializerSettings = new JsonSerializerSettings();
jsonSerializerSettings.ContractResolver = new PublishedContentContractResolver();
var jsonStr = JsonConvert.SerializeObject(items, Formatting.Indented, jsonSerializerSettings);
However, when I do that and echo the JSON string in the template, all the rich text editor properties come back as just {}. In other words, all the content is stripped from the JSON.
How can I get the rich text editor content to be in the JSON as well? Thank you.
Hi,
I tried the item serialization first on Umbraco 7, and it worked perfectly, with the additional handling of the rich text editor, as described here, but on Umbraco 8.2.2 - no properties are being serialized, I only get the key, Name, Id, level, path etc. properties. Did anyone else encounter this? Thanks
How do I convert rich text editor doctype properties to JSON in Umbraco 8?
I have a doctype with several properties that are rich text editors. I can grab a list of content items with this doctype with a standard query like the following:
Then, I convert the
items
variable to JSON with the following:However, when I do that and echo the JSON string in the template, all the rich text editor properties come back as just
{}
. In other words, all the content is stripped from the JSON.How can I get the rich text editor content to be in the JSON as well? Thank you.
It's not clear from your example, what your PublishedContractResolver is.
Assuming it's the one from the Contentment package by Lee Kelleher?
https://github.com/leekelleher/umbraco-contentment/blob/839e4828f65c7e2e8fe317d6c898648305f2ab1c/src/Umbraco.Community.Contentment/Web/Serialization/PublishedContentContractResolver.cs
I tested it as well, and the rte data wasn't being rendered. Found this post on stack overflow:
https://stackoverflow.com/questions/11350392/how-do-i-serialize-ihtmlstring-to-json-with-json-net/11350394
So took the converter example and plugged it into Lee's example:
Then the rte's are being rendered out! hope that helps.
Thank you. it works for me
That's very helpful. Thanks a ton!
Hi, I tried the item serialization first on Umbraco 7, and it worked perfectly, with the additional handling of the rich text editor, as described here, but on Umbraco 8.2.2 - no properties are being serialized, I only get the key, Name, Id, level, path etc. properties. Did anyone else encounter this? Thanks
is working on a reply...