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
Post a Comment