이를 위해 parse()와 함께 replace()를 사용할 수 있습니다. 다음은 코드입니다 -
예시
var studentDetails = `"{""name"": ""John"",""subjectName"":
""Introduction To JavaScript""}"`;
console.log("The actual object=");
console.log(studentDetails);
var removeFirstAndLast = studentDetails.substring(1,studentDetails.length-1)
var removeDoubleQuotes = removeFirstAndLast.replace(/""/gi, `"`)
console.log(removeDoubleQuotes)
var output = JSON.parse(removeDoubleQuotes);
console.log(output); 위의 프로그램을 실행하려면 다음 명령을 사용해야 합니다 -
node fileName.js.
여기에서 내 파일 이름은 demo103.js입니다.
출력
이것은 다음과 같은 출력을 생성합니다 -
PS C:\Users\Amit\JavaScript-code> node demo103.js
The actual object=
"{""name"": ""John"",""subjectName"": ""Introduction To JavaScript""}"
{"name": "John","subjectName": "Introduction To JavaScript"}
{ name: 'John', subjectName: 'Introduction To JavaScript' }