javascript - how to json.stringify() a string -


i have complex object stored string in text file

this data reading text file

 [  {     name: "v",     number: 20,     coords: {         "cn": {              points: [                 [23,32,32],                 [32,32,32]             ],              b: "vc",              label: "ds"         }     } }] 

i want convert json string note:- cant use eval function have tried json.stringify getting output:-

"   [\r\n     {\r\n        name: \"v\",\r\n        number: 20,\r\n        coords: {\r\n            \"cn\": { \r\n                points: [\r\n                    [23,32,32],\r\n                    [32,32,32]\r\n                ], \r\n                b: \"vc\", \r\n                label: \"ds\"\r\n            }\r\n        }\r\n    }]" 

you can use combination of eval() , json.stringify(). eval() convert valid javascript object , can use json.stringify() convert json string.

var str='[\   {\      name: "v",\      number: 20,\      coords: {\          "cn": { \              points: [\                  [23,32,32],\                  [32,32,32]\              ], \              b: "vc", \              label: "ds"\          }\      }\  }]';    document.write(json.stringify(eval(str)));


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -