Normal form submission vs. JSON

后端 未结 5 2042
生来不讨喜
生来不讨喜 2021-02-05 04:09

I see advantages of getting JSON response and formatting in client side but are there any advantages by using JSON for form submission compared to normal submission?

5条回答
  •  迷失自我
    2021-02-05 05:06

    One thing comes to mind when dealing with POST data is useless repetition:

    For example, in POST we have this:

    partners[]=Apple&partners[]=Microsoft&partners[]=Activision
    

    We can actually see, that there is a lot of repetition here, where as when we are sending JSON:

    {"partners":["Apple","Microsoft","Activision"]}
    

    59 characters versus 47. In this small sample it looks miniscule, but these savings could go up and up, and even several bytes will save you some data. Of course, there is the parsing of data on server side, which could even out the differences, but still, i saw this sometimes helping when dealing with slower connections (looking at you, 3G and EDGE).

提交回复
热议问题