<!DOCTYPE html> <html> <head> <title>JavaScript对象转JSON字符串</title> </head> <body> <script> var jsonObj = { "userId": "admin", "password": "123456", "code": "428m", "sessionId": "64F3124042EC11EDB8F1974F809A2BE6", "userinfo": [ { "username": "dddddd", "sex": "男", "add": "深圳南山" }, { "member": true, "level": 5 } ] } //json串 console.log(jsonObj) //获取姓名 console.log(jsonObj.userinfo[0].username); //json对象转String var userString = JSON.stringify(jsonObj); console.log(userString); //string转JSON var userJson = JSON.parse(userString); console.log(userJson); </script> </body> </html>
标签:jsonObj,javaScript,console,log,--,javascript,JSON,json,userString From: https://www.cnblogs.com/dwdw/p/16750604.html