如何将表单值转换为JSON格式 [英] How to convert form values into json format

查看:312
本文介绍了如何将表单值转换为JSON格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在控制器中创建json对象,如果可能的话,
您能否提供示例代码以在控制器中创建json

is it possible to create json object in the controller,If possible,
can u provide sample code to create json in the controller

推荐答案



我希望这个问题仍然存在:)

看来您使用的是ASP.NET MVC,对吧?
如果要直接从操作中返回Json对象,则只需编写以下内容:

Hi,

I hope this question is still opened :)

It seems that you use ASP.NET MVC, right?
If you want to return a Json object directly from your action, you can just write the following:

return new JsonResult { Data = new { Test1 = "asdf", Test2 = "qwer" } };



如果您已经有一个包含要返回的数据的变量,则可以通过以下方式进行操作:



if you already have a variable containing the data you want to return, you can do it this way:

return new JsonResult { Data = yourDataObject };



希望这会有所帮助.


致以诚挚的问候,祝您编程愉快,
克里斯



Hope this helps.


Best regards and happy coding,
Chris


这篇关于如何将表单值转换为JSON格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆