将值对发送到服务器

将值对发送到服务器

问题描述:

I need to send a bunch of pairs of values to a PHP server (and being "pairs", each of the two values are related), and will be using a GET request. Either of the following will work. What is the correct way to do this?

[{a:123,b:321}, {a:111,b:222}, {a:333,b:111}, {a:222,b:111}, ...]

or

[123,111,333,222] and [321,222,111,111]

我需要向PHP服务器发送一堆值(并且是“对”,每个都是 两个值相关),并将使用GET请求。 以下任何一种都可以使用。 这样做的正确方法是什么? p>

  [{a:123,b:321},{a:111,b:222},{a:333,b  :111},{a:222,b:111},...] 
  code>  pre> 
 
 

或 p>

   [123,111,333,222]和[321,222,111,111] 
  code>  pre> 
  div>

There is not good or bad way. You just need to send data and both ways seem proper. Only advantange of second way is that it is compressed and pass lesser data through network while first one can help you to write lesser code as you can directly use json libraries.

If data usage in not a concern then you should go with first method as it will be more convenient to handle via code.

If the usage is from the perspective of some third person who uses the API, the it depends on how the data is related. If pair of a and b is related, then first way is preferred but if all a's are related together and b's are related separately the second way should be used.