Is there an easy way to get json from a selection. At the moment I have a string builder that builds the json using a foreach loop. I'm after something like this:
var selection = CurrentPage.Site().Children("ShowcaseItem").Where("Visible");
var json = Json.Encode(selection);
Please let me know if I'm living in a dream world or if something like this is possible.
JSON from a selection RAZOR syntax
Hello.
Is there an easy way to get json from a selection. At the moment I have a string builder that builds the json using a foreach loop. I'm after something like this:
Please let me know if I'm living in a dream world or if something like this is possible.
Leon
Hi Leon,
Try to see this post https://our.umbraco.org/forum/developers/razor/59710-list-nodes-as-json-with-parameters, where Claus are getting JSON, the only thing that I can see that is different is that he retuns it as a string instead for a variable, so perhaps the post can help you further.
Hope this helps,
/Dennis
Thanks Dennis,
The simple
string json =Json.Encode(items);
didn't work, but I used the code from the link you sent me and that works.Thank you very much for your help.
Leon
Hej Leon,
Great that you managed to solve it, and glad that I could help you on the right track :-)
/Dennis
is working on a reply...