#1 Working with JSON Data
The samples can differ based on your Razor base class or if you're running an old version.
Switch to Typed (2sxc 16+) Switch to Dynamic (Razor14 or below)
Switch to Typed (2sxc 16+) Switch to Dynamic (Razor14 or below)
Working with JSON Data
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.
⬇️ Result | Source ➡️
- Title: This is a JSON title
- IsCool: True
- Sub-item title: sub-item title
- Is this a list/array? False
- Are the tags a list? True
⬇️ Result | Source ➡️
System.Collections.Generic.List`1[System.Object]
- some tag
- another tag
- a third tag
⬇️ Result | Source ➡️
-
title (System.String)
= This is a JSON title -
isCool (System.Boolean)
= True -
subItem (ToSic.Sxc.Data.Internal.Typed.WrapObjectTyped)
= { "title": "sub-item title" } -
tags (System.Collections.Generic.List`1[System.Object])
= System.Collections.Generic.List`1[System.Object]
#1 Working with JSON Data