English 中文(简体)
Node.js - Send and receive Array as GET/POST using querystring
原标题:Node.js - Send and receive Array as GET/POST using querystring

我引用以下法典,但似乎不可行:

var post_req = {
    array: [
        [ {
            param1:  something ,
            param2: 123
        } ],
        [ ],
        [ ],
        [ {
            param2:  something ,
            param4: 1234,
            param1:  hello 
        } ]
    ]
};
var data_send = querystring.stringify(post_req);

var request = client.request( POST ,  / , headers);
request.end(data_send);

以及

if( req.method ==  POST  ) {
    req.addListener( data , function(chunk)
    {
        POST = querystring.parse(chunk);
        console.log(POST);
    }
}

最后,我有5个子宫,与物体中的5个参数相对应,但外加][其名称的特性:

{ array: 
   [ {  ][param1 :  something  }
   , {  ][param2 :  123  }
   , {  ][param2 :  something  }
   , {  ][param4 :  1234  }
   , {  ][param1 :  hello  }
   ]
}
最佳回答

有一个新的分点,可以确定:“零件装置”。

https://github.com/ljharb/qs

"query string parser for node supporting nesting, as it was removed from 0.3.x, so this library provides the previous and commonly desired behaviour (and twice as fast)"

如果任何人能够告诉我,为什么从0.3.x中删除,我将请你发表评论。 (我希望我恢复对Node.js的信任。)

问题回答

Don t use querystring. 重新计算被派作扼杀的JSON物体。 而是使用JSON.parse。 并且使用JSON。 说明而不是提问。 强化

当你寄出圆形的参数时,或当你填表时,便宜进行查询。 但是,如果你只派一名有你所有数据的JSON物体,就没有使用该物体。

在你的设想中,我将不使用已经包括的JSON图书馆。 这将更清洁和更快。





相关问题
Getting QueryStrings from WebRequest

Lets say i have this: WebRequest myWebRequest1 = (WebRequest)asynchronousResult.AsyncState; i know that i can get the url like this myWebRequest1.RequestUri but i was wondering if there is any way ...

How should I process the values of optional Query Strings?

I m pretty new to C# and ASP.NET, so bear with me on this one. I m setting up a page that receives query strings from the url. It then passes these strings to another method (in another class, ...

How to get the QueryString from an ashx file?

There is an ashx file containing "ProcessRequest(HttpContext context)" method which gets triggered automatically. When and how does it get fired? Another question, How can I get the current ...

asp.net consecutive are backslashes removed from url

I m having an issue in my ASP.NET web app where intentionally consecutive backslashes are being removed from the request url. I ll request something like: localhost/Page/A//C But when the request ...

convert guid tostring in javascript .net

How do I convert guid to string in javascript. I am getting guid from the querystring, and m not able to process it as is. I have tried the following ways to do it but it doesnt seem to work. var ...

热门标签