格式化 Freemarketnet 中的数据
formatting data in Freemarketnet
我正在使用 freemarketnet 将宏替换为适当的内容。为此,我从 mvc 控制器发送 json 对象进行查看。在视图中,我想以对象格式阅读 json。
这是我的代码
<#import "../Shared/Master.ftl" as layout />
<#assign TitleContent in layout>
Home Page
</#assign>
<#assign Recipient = controller.ViewData.data>
${Recipient}
在我的 controller.cs
dynamic obj = JObject.Parse("{'contact':{ 'cx_outstandingamountid':{
'cx_outstandingamount':'ytest' } } }");
ViewData["data"] = obj;
return View();
现在视图呈现为
{'contact':{ 'cx_outstandingamountid':{'cx_outstandingamount':'ytest' } } }
但我想呈现为 'ytest'。为此,我尝试了
${Recipient.contact.cx_outstandingamountid.cx_outstandingamount}
但是没有用。谁能帮帮我?
我们需要使用eval来解析freemarker中的json。参考here。
<#assign recip=controller.ViewData.data>
<#assign Recipient = recip?eval>
${Recipient.contact.acsi_outstandingamountid.acsi_outstandingamount}
我正在使用 freemarketnet 将宏替换为适当的内容。为此,我从 mvc 控制器发送 json 对象进行查看。在视图中,我想以对象格式阅读 json。
这是我的代码
<#import "../Shared/Master.ftl" as layout />
<#assign TitleContent in layout>
Home Page
</#assign>
<#assign Recipient = controller.ViewData.data>
${Recipient}
在我的 controller.cs
dynamic obj = JObject.Parse("{'contact':{ 'cx_outstandingamountid':{
'cx_outstandingamount':'ytest' } } }");
ViewData["data"] = obj;
return View();
现在视图呈现为
{'contact':{ 'cx_outstandingamountid':{'cx_outstandingamount':'ytest' } } }
但我想呈现为 'ytest'。为此,我尝试了
${Recipient.contact.cx_outstandingamountid.cx_outstandingamount}
但是没有用。谁能帮帮我?
我们需要使用eval来解析freemarker中的json。参考here。
<#assign recip=controller.ViewData.data>
<#assign Recipient = recip?eval>
${Recipient.contact.acsi_outstandingamountid.acsi_outstandingamount}