Node.js - Send and receive Array as GET/POST using querystring

后端 未结 3 607
太阳男子
太阳男子 2021-01-04 07:39

I\'ve got the following code, but it doesn\'t seem to work:

var post_req = {
    array: [
        [ {
            param1: \'something\',
            param2:          


        
3条回答
  •  长情又很酷
    2021-01-04 08:09

    To confirm my comment above, node's querystring.stringify function won't handle nested arrays (at the time of writing).

    You can see the source of stringify at https://github.com/ry/node/blob/master/lib/querystring.js

    Note that it handles one level of arrays but it doesn't recurse. When it finds an array it uses stringifyPrimitive to encode the array's values. You can see that stringifyPrimitive doesn't handle arrays, only number, boolean and string.

    As I suggested in my comment, given that you're using a POST request a better idea would be to use JSON encoding for your complex data structure.

    Or use https://github.com/visionmedia/node-querystring as suggested by @FriendlyDev

提交回复
热议问题