将值对发送到服务器

时间:2016-10-15 16:51:48

标签: php json rest url get

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

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

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

1 个答案:

答案 0 :(得分:0)

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.