Reputation: 119
This must be something very obvious but I spent enough time on it:
Node express gets a JSON object that was set in the browser. the object name is dddd.
when I:
console.log(req.params.dddd);
I get:
{"email":"[email protected]"}
which is correctly what I set to node.js
but when I:
console.log(req.params.dddd.email);
I get undefined
...
I must be missing the point on this one. Than you to anyone helping
Upvotes: 1
Views: 284
Reputation: 441
try {
var obj = JSON.parse( req.params.dddd);
} catch (e) {
console.log("parsing error!!!")
}
console.log(obj.email)
Always use try ... catch
block while using JSON.parse
method.
Upvotes: 0
Reputation: 26536
I think you get a string and you mistakenly think it's a JSON. try JSON.parse before.
var obj = JSON.parse( req.params.dddd);
console.log(obj.email)
Upvotes: 6