即使在发布时,我也可以IContent通过侦听器处理来自 Umbraco 的对象
public static IContent[] FaqEntities(this PublishEventArgs<IContent> publishEventArgs)
{
return publishEventArgs.PublishedEntities.Where(x => x.ContentType.Name == "FAQ").ToArray();
}
在 C# 中,我想JSON从返回的数组中的已发布文档中创建一个包含选定属性(别名和值)的文件 - 是否有一种简单的方法可以序列化 UmbracoIContent对象以获得我需要的 JSON 输出?
var json = JsonConvert.SerializeObject(faqEntities)并且 var json = Json.Encode(faqEntities)只给了我整个对象,但我希望创建一个类似于
{
"faqs": [{
"nodeId": 1,
"question": "My Password is incorrect?",
"answer": "If you have forgotten or lost your password, please click on the Forgotten Password link on the Login page and follow the instructions shown."
},
{
"nodeId": 2,
"question": "How can I edit my personal details?",
"answer": "You can blah blah blah....."
},
{
"nodeId": 3,
"question": "What is an ABC?",
"answer": "An ABC is where you can....."
}
]
}
一旦检索到 IContent 以转换为 JSON,是否有一种简单的方法?