Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Leon 101 posts 489 karma points
    Feb 06, 2015 @ 12:42
    Leon
    0

    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:

    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.

    Leon

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Feb 06, 2015 @ 12:49
    Dennis Aaen
    0

    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.

    var selection = CurrentPage.Site().Children("ShowcaseItem").Where("Visible");
    string json = Json.Encode(selection);

    Hope this helps,

    /Dennis


     

  • Leon 101 posts 489 karma points
    Feb 06, 2015 @ 15:39
    Leon
    100

    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

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Feb 06, 2015 @ 15:41
    Dennis Aaen
    0

    Hej Leon,

    Great that you managed to solve it, and glad that I could help you on the right track :-)

    /Dennis

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies