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)
@inherits Custom.Hybrid.RazorTyped @using System.Collections; @{ var someJson = System.IO.File.ReadAllText(App.Folder.PhysicalPath + "/tutorials/json-use/demo.json"); var thing = Kit.Json.ToTyped(someJson); } <ul> <li>Title: @thing.String("Title") </li> <li>IsCool: @thing.Bool("IsCool") </li> <li>Sub-item title: @thing.String("SubItem.Title") </li> <li>Is this a list/array? @(thing is IEnumerable) </li> <li>Are the tags a list? @(thing.Get("Tags") is IEnumerable) </li> </ul>
{ "title": "This is a JSON title", "isCool": true, "subItem": { "title": "sub-item title" }, "tags": [ "some tag", "another tag", "a third tag" ] }
@inherits Custom.Hybrid.RazorTyped @{ var someJson = System.IO.File.ReadAllText(App.Folder.PhysicalPath + "/tutorials/json-use/demo.json"); var thing = Kit.Json.ToTyped(someJson); } @thing.Get("Tags") <ol> @foreach (var tag in thing.Get("Tags") as IEnumerable<object>) { <li>@tag</li> } </ol>
@inherits Custom.Hybrid.RazorTyped @using System.Collections; @{ var someJson = System.IO.File.ReadAllText(App.Folder.PhysicalPath + "/tutorials/json-use/demo.json"); var thing = Kit.Json.ToTyped(someJson); } <ol> @foreach (var prop in thing.Keys()) { <li> <strong>@prop</strong> (@thing.Get(prop).GetType()) <br> = @thing.Get(prop) </li> } </ol>