I am sending the string from AngularJS to NodeJS in following form.
"{↵obj:{↵one:string,↵two:integer↵}↵}"//request object from browser console
I want to convert this string in object and use its properties.for this the server side code is following:
var data=req.body.data.replace(/"/g,"");
var str=data.replace(/\n/g," ");
//res.json(str) // returning "{ obj:{ one:string, two:integer } }"
try {
var obj=JSON.parse(JSON.stringify(str)).replace(/"/g,"");
res.json(obj);//returning same "{ obj:{ one:string, two:integer } }"
} catch (error) {
console.log(error);
}
I want to get ['users'] by Object.keys[obj] or by any other method want to access the properties of this object.but failed to achieve this.
Many solutions like This couldn't be helpful.any suggestion here??
JSON.parse()onreq.body.data.