Req.query. Parameter names are often used when using Nodejs to get the values of a parameter
For example
Url:http://localhost:7778/project?id=1
<span style= "FONT-SIZE:18PX;" >var id = req.query.idconsole.log (ID);//print out URL id parameter value 1 </span>
However, there is a problem when the parameters in the URL are in JSON format
Url:http://localhost:7778/project?mainmember={id:1}
The values for printing mainmember and mainmember.id find that mainmember can print normally, but mainmember.id is undefined, such as
Later, I used typeof to print the type of mainmember and found it to be a string. It should be in the data transfer process, JSON is passed as a string of characters , and JS operation is a JSON object, so, to convert the string JSON into a JSON object
Modify the following code:
var main = Req.query.mainMember; var mainmember = eval ("(" + main + ")");//convert string JSON to JSON Object Console.log (mainmember); Console.log (mainmember.id);
The print results are correct.
Suddenly worry about passing arrays also need to convert ~ ~ ~
Nodejs get the JSON-formatted parameters in the URL