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

后端 未结 3 608
太阳男子
太阳男子 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:13

    Don't use querystring.parse for recreating a JSON object sent as string. Use instead JSON.parse. And use JSON.stringify instead of querystring.stringify

    querystring is useful when you send parameter encoded in the url or when you post a form. But there is no point in using it if you send just one JSON object with all your data.

    In your scenario I would dismiss the querystring library and use JSON library, which is already included. It would be cleaner and faster.

    http://www.json.org/js.html

提交回复
热议问题