javascript - JSON parse object -


i have following json string comes http request:

{ '{firstname:\'joe\'}': '' } // output of console.log(req.body); 

i have tried print value console using:

console.log(req.body.firstname); 

but says value undefined. how can value of firstname?

to see client doing how sends json request:

//angular2 headers.append('content-type', 'application/x-www-form-urlencoded');         this.http.post(             'http://192.168.1.45:3000/test',              json.stringify({firstname:'joe'}), //this parameter want             {headers:headers}         ) 

converts array json string using json.stringify, , converts string array using json.parse

<html>     <head>     <script>     function gettz(){      var str=json.stringify({firstname:'joe'});      console.log(str);      //parse object       dataobj = json.parse(str);     // object property       console.log(dataobj.firstname);     }      </script>     </head>      <body>         <input type="button" id="button" value="printjson" onclick="gettz();">      </body>      </html> 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -