<img>
JSON data can be tricky. The easiest way is to convert it to a dynamic object using AsDynamic(string). Then you can easily use it in your code.
AsDynamic(string)
Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials. Click to expand the code
{ "title": "This is a JSON title", "isCool": true, "subItem": { "title": "sub-item title" }, "tags": [ "some tag", "another tag", "a third tag" ] }
@inherits Custom.Hybrid.Razor14 @{ var someJson = System.IO.File.ReadAllText(App.PhysicalPath + "/json/demo.json"); var thing = AsDynamic(someJson); } <!-- unimportant stuff, hidden --> <hr> <h3>Show properties and sub-properties - case insensitive</h3> <ul> <li>Title: @thing.Title</li> <li>Description: @thing.IsCool</li> <li>Sub-item title: @thing.SubItem.Title</li> <li>Is this a list/array? @thing.IsList </li> <li>Are the tags a list? @thing.Tags.IsList </li> </ul> <hr> <h3>Going through a list</h3> <ol> @foreach(var tag in thing.Tags) { <li>@tag</li> } </ol> <!-- unimportant stuff, hidden -->