发布JSON与传统表单编码数据作为提交表单的数据格式

时间:2022-10-24 14:06:31

posting JSON vs traditional form encoding as the data format for submitting data to the server from a HTML form. The HTML form is dynamic as in, the user can add new rows (for example) and fill in data. There is an argument that using form fields with an MVC framework is easier in this case since the MVC framework like Spring MVC takes care of the bindings to the form (generating id's in the dynamically generated HTML etc) and we can have an object on the controller to collect these values when the form is posted using AJAX as a form encoded content type.

将JSON与传统表单编码一起发布为从HTML表单向服务器提交数据的数据格式。 HTML表单是动态的,用户可以添加新行(例如)并填写数据。有一个论点是在这种情况下使用带有MVC框架的表单字段更容易,因为像MV MVC这样的MVC框架负责处理表单(在动态生成的HTML中生成id等),我们可以在当使用AJAX作为表单编码内容类型发布表单时,控制器收集这些值。

I was thinking of using JSON, what are your views?

我在考虑使用JSON,你有什么看法?

  1. Is using form encoded format (the traditional way) the better option or is it using JSON as the payload the way to go? What are some of the pros and cons you have encountered?
  2. 使用表单编码格式(传统方式)是更好的选择还是使用JSON作为有效负载的方式?您遇到的一些优点和缺点是什么?
  3. Are web applications using JSON as the data format for submitting forms?
  4. Web应用程序是否使用JSON作为提交表单的数据格式?
  5. We currently do not have any integration with mobile apps etc so is it worth doing JSON over traditional form fields approach?
  6. 我们目前没有与移动应用程序等进行任何集成,因此是否值得使用传统表单字段方法进行JSON?

Thanks for your time.

谢谢你的时间。

5 个解决方案

#1


-2  

Is using form fields the better option or is it using JSON the way to go?

使用表单字段是更好的选择还是使用JSON的方式去?

You are comparing apples with hammers. JSON is data format while form is, well, let's say, data source. You can send JSON data in HTML form fields, so this question is bit odd.

你正在用锤子比较苹果。 JSON是数据格式,而形式就是数据源。您可以在HTML表单字段中发送JSON数据,因此这个问题有点奇怪。

Are web applications using JSON for submitting forms?

Web应用程序是否使用JSON提交表单?

HTML forms? No

HTML表单?没有

We currently do not have any integration with mobile apps etc so is it worth doing JSON over traditional form fields approach?

我们目前没有与移动应用程序等进行任何集成,因此是否值得使用传统表单字段方法进行JSON?

Again - read about the technologies you want to use. This helps to understand what it is. Do not start implementation prior getting elementary knowledge or you end wasting your time "refactoring" your project. From scratch...

再次 - 阅读您想要使用的技术。这有助于理解它是什么。在获得基础知识之前不要开始实施,否则你会浪费时间“重构”你的项目。从头开始...

#2


6  

1. Is using form fields the better option or is it using JSON the way to go?

You can't compare this. What you can say is, either the traditional Submit is better or JSON way, but you need to take a choice. When submitting through JSON, you cannot send files, but it needs AJAX or similar technology to talk to the server. So browser compatibility to be checked.

你不能比较这个。您可以说,传统提交更好或JSON方式,但您需要做出选择。通过JSON提交时,您无法发送文件,但需要使用AJAX或类似技术与服务器通信。因此要检查浏览器兼容性。

2. Are web applications using JSON for submitting forms?

The question itself is wrong. No is the answer, because most of the forms are submitted by POST and the values are sent as serialized, which doesn't always mean JSON.

问题本身是错误的。答案是肯定的,因为大多数表单都是通过POST提交的,并且值是按序列化的,这并不总是意味着JSON。

3. We currently do not have any integration with mobile apps etc so is it worth doing JSON over traditional form fields approach?

Again, the browser compatibility and users' bandwidth play a major role. If people have good browsers, go for it.

同样,浏览器兼容性和用户带宽起着重要作用。如果人们有好的浏览器,那就去吧。

My suggestion:

There are a set of rules and best practices available for designing web applications of all kinds. Kindly go through it and work on your project. :)

有一套规则和最佳实践可用于设计各种Web应用程序。请仔细阅读并完成您的项目。 :)

#3


3  

I would recommend that you stick with the standard format for the framework that you are using. In terms of performance, security and reliability the people developing your framework will generally do a much better job than you will at developing such infrastructure.

我建议您坚持使用您正在使用的框架的标准格式。在性能,安全性和可靠性方面,开发框架的人员通常比开发此类基础架构的工作要好得多。

This article Normal form submission vs. JSON has a bit of a discussion on the topic of basic form submission vs JSON submission. One point which I agree with is that when you start getting into complex data structures, a structured format as opposed to a flat one can be quite advantageous. That said, as you said yourself, Spring MVC and other similar frameworks take care of the binding. For me, this is the one thing that JSON can do significantly better than standard form submission. If it is taken care of by default by the framework, stick with the default. Don't go adding complexity where it isn't necessary.

本文正常表单提交与JSON对基本表单提交与JSON提交的主题进行了一些讨论。我同意的一点是,当你开始涉及复杂的数据结构时,结构化格式而不是平面格式可能是非常有利的。也就是说,就像你自己说的那样,Spring MVC和其他类似的框架负责绑定。对我来说,这是JSON可以比标准表单提交做得更好的一件事。如果框架默认处理它,请坚持使用默认值。不要在没有必要的地方添加复杂性。

#4


1  

Do you have any specific reason to post JSON?

你有什么特别的理由发布JSON吗?

If not, then I would say that the default choise would be to post form-data, as that is natively supported by all browsers and all servers. You can post form-data without any client script at all, and any server implemenation handles it by default.

如果没有,那么我会说默认选择是发布表单数据,因为所有浏览器和所有服务器本身都支持它。您可以在没有任何客户端脚本的情况下发布表单数据,并且任何服务器实现都会默认处理它。

#5


0  

Update. Give a look to http://www.w3.org/TR/html-json-forms/

更新。请访问http://www.w3.org/TR/html-json-forms/

But "Beware. This specification is no longer in active maintenance and the HTML Working Group does not intend to maintain it further.".

但是“注意。此规范不再处于主动维护状态,HTML工作组也不打算进一步维护它。”

#1


-2  

Is using form fields the better option or is it using JSON the way to go?

使用表单字段是更好的选择还是使用JSON的方式去?

You are comparing apples with hammers. JSON is data format while form is, well, let's say, data source. You can send JSON data in HTML form fields, so this question is bit odd.

你正在用锤子比较苹果。 JSON是数据格式,而形式就是数据源。您可以在HTML表单字段中发送JSON数据,因此这个问题有点奇怪。

Are web applications using JSON for submitting forms?

Web应用程序是否使用JSON提交表单?

HTML forms? No

HTML表单?没有

We currently do not have any integration with mobile apps etc so is it worth doing JSON over traditional form fields approach?

我们目前没有与移动应用程序等进行任何集成,因此是否值得使用传统表单字段方法进行JSON?

Again - read about the technologies you want to use. This helps to understand what it is. Do not start implementation prior getting elementary knowledge or you end wasting your time "refactoring" your project. From scratch...

再次 - 阅读您想要使用的技术。这有助于理解它是什么。在获得基础知识之前不要开始实施,否则你会浪费时间“重构”你的项目。从头开始...

#2


6  

1. Is using form fields the better option or is it using JSON the way to go?

You can't compare this. What you can say is, either the traditional Submit is better or JSON way, but you need to take a choice. When submitting through JSON, you cannot send files, but it needs AJAX or similar technology to talk to the server. So browser compatibility to be checked.

你不能比较这个。您可以说,传统提交更好或JSON方式,但您需要做出选择。通过JSON提交时,您无法发送文件,但需要使用AJAX或类似技术与服务器通信。因此要检查浏览器兼容性。

2. Are web applications using JSON for submitting forms?

The question itself is wrong. No is the answer, because most of the forms are submitted by POST and the values are sent as serialized, which doesn't always mean JSON.

问题本身是错误的。答案是肯定的,因为大多数表单都是通过POST提交的,并且值是按序列化的,这并不总是意味着JSON。

3. We currently do not have any integration with mobile apps etc so is it worth doing JSON over traditional form fields approach?

Again, the browser compatibility and users' bandwidth play a major role. If people have good browsers, go for it.

同样,浏览器兼容性和用户带宽起着重要作用。如果人们有好的浏览器,那就去吧。

My suggestion:

There are a set of rules and best practices available for designing web applications of all kinds. Kindly go through it and work on your project. :)

有一套规则和最佳实践可用于设计各种Web应用程序。请仔细阅读并完成您的项目。 :)

#3


3  

I would recommend that you stick with the standard format for the framework that you are using. In terms of performance, security and reliability the people developing your framework will generally do a much better job than you will at developing such infrastructure.

我建议您坚持使用您正在使用的框架的标准格式。在性能,安全性和可靠性方面,开发框架的人员通常比开发此类基础架构的工作要好得多。

This article Normal form submission vs. JSON has a bit of a discussion on the topic of basic form submission vs JSON submission. One point which I agree with is that when you start getting into complex data structures, a structured format as opposed to a flat one can be quite advantageous. That said, as you said yourself, Spring MVC and other similar frameworks take care of the binding. For me, this is the one thing that JSON can do significantly better than standard form submission. If it is taken care of by default by the framework, stick with the default. Don't go adding complexity where it isn't necessary.

本文正常表单提交与JSON对基本表单提交与JSON提交的主题进行了一些讨论。我同意的一点是,当你开始涉及复杂的数据结构时,结构化格式而不是平面格式可能是非常有利的。也就是说,就像你自己说的那样,Spring MVC和其他类似的框架负责绑定。对我来说,这是JSON可以比标准表单提交做得更好的一件事。如果框架默认处理它,请坚持使用默认值。不要在没有必要的地方添加复杂性。

#4


1  

Do you have any specific reason to post JSON?

你有什么特别的理由发布JSON吗?

If not, then I would say that the default choise would be to post form-data, as that is natively supported by all browsers and all servers. You can post form-data without any client script at all, and any server implemenation handles it by default.

如果没有,那么我会说默认选择是发布表单数据,因为所有浏览器和所有服务器本身都支持它。您可以在没有任何客户端脚本的情况下发布表单数据,并且任何服务器实现都会默认处理它。

#5


0  

Update. Give a look to http://www.w3.org/TR/html-json-forms/

更新。请访问http://www.w3.org/TR/html-json-forms/

But "Beware. This specification is no longer in active maintenance and the HTML Working Group does not intend to maintain it further.".

但是“注意。此规范不再处于主动维护状态,HTML工作组也不打算进一步维护它。”