我需要向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]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]最满意答案
没有好的或坏的方式。 你只需要发送数据,这两种方式似乎都是正确的。 第二种方式的优点是,它被压缩并通过网络传递较少的数据,而第一个可以帮助您编写较小的代码,因为您可以直接使用json库。
如果不关心数据使用情况,那么您应该使用第一种方法,因为通过代码处理会更方便。
如果从使用API的第三方角度看,这取决于数据的相关性。 如果a和b是相关的,那么首选的方式是首选,但如果所有的a's都相关在一起,并且b's是分开关联b's则应该使用第二种方式。
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.
更多推荐
GET,PHP,使用,电脑培训,计算机培训,IT培训"/> <meta name="description"
发布评论