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
Seing as json seems to be the data format of choice these days :) i guess it should be very simple to render json to html in razor... I just cant seem to find a way to do it. Say i have a simple chunk of json like this:
[{ "skole":"skole1", "link":"link1", }, { "skole":"skole2", "link":"link2", }]
How would one go about rendering this data in, lets say, an unordered list?:
<ul> <li>skole1, link1</li> <li>Skole2, link2</li> </ul>
Hi Claushingebjerg,
I tend to use Newtonsoft's JSON.Net and JArrays. This is a dynamic example - you might want to create a relevant class and parse it .
@using Newtonsoft.Json.Linq @{ string jsonTest = @"[{ ""skole"":""skole1"", ""link"":""link1"", }, { ""skole"":""skole2"", ""link"":""link2"", }]"; var jArray = JArray.Parse(jsonTest); if (jArray.Count > 0) { <ul> @foreach (dynamic x in jArray) { <li>@x.skole, @x.link</li> } </ul> } }
More info here: http://www.newtonsoft.com/json/help/html/QueryJsonDynamic.htm
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Rendering json as html
Seing as json seems to be the data format of choice these days :) i guess it should be very simple to render json to html in razor... I just cant seem to find a way to do it. Say i have a simple chunk of json like this:
How would one go about rendering this data in, lets say, an unordered list?:
Hi Claushingebjerg,
I tend to use Newtonsoft's JSON.Net and JArrays. This is a dynamic example - you might want to create a relevant class and parse it .
More info here: http://www.newtonsoft.com/json/help/html/QueryJsonDynamic.htm
is working on a reply...