Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将形式转换为对象_Javascript_Node.js_Express - Fatal编程技术网

Javascript 将形式转换为对象

Javascript 将形式转换为对象,javascript,node.js,express,Javascript,Node.js,Express,使用node.js和express…假设有一个表单包含以下字段: <form action="/test" method="post"> <input name="name" value="zzz" /> <input name="test[0].name" value="a" /> <input name="test[0].value" value="b" /> <input name="test[1].na

使用node.js和express…假设有一个表单包含以下字段:

<form action="/test" method="post">
    <input name="name" value="zzz" />
    <input name="test[0].name" value="a" />
    <input name="test[0].value" value="b" />
    <input name="test[1].name" value="c" />
    <input name="test[1].value" value="d" />
</form>
我怎样才能得到像这样的物体呢

{
    'name: 'zzz',
    'test': [
        { 'name': 'a', 'value': 'b'},
        { 'name': 'c', 'value': 'd'}
    ]
}

这是一个将表单解析为Ruby等对象的对象。

在服务器上如何解析请求主体?如果应用正在使用,这是扩展格式。啊,明白了,似乎express生成的默认值是app.usebodyParser.urlencoded{extended:false};
{
    'name: 'zzz',
    'test': [
        { 'name': 'a', 'value': 'b'},
        { 'name': 'c', 'value': 'd'}
    ]
}