@foreach (var fieldset in Model.Content.GetPropertyValue<ArchetypeModel>("MainMenuDT"))
{
<li>@fieldset.GetValue("linkObj")</li>
}
这个输出:[
{
"caption":"gjhg",
"link":"http://localhost:2081/",
"newWindow":false,
"edit":false,
"isInternal":false,
"type":"external",
"title":"gjhg"
}
]
如何获取linkObj的值?链接元素从JSON字符串?
我真的不知道Model.Content.GetPropertyValue<ArchetypeModel>("MainMenuDT")
返回什么,但它真的很容易解析json使用JSON.net
:
public class MyObject
{
public string caption {get;set;}
public string link {get;set;}
public bool newWindow {get;set;}
public bool edit {get;set;}
public bool isInternal {get;set;}
public string type{get;set;}
public string title{get;set;}
}
List<MyObject> obj = JsonConvert.DeserializeObject<List<MyObject>>(json); // json is a string
if(obj.Count > 0)
{
string link = obj[0].link;
}