1
json = "{ elements: [ {type: 'radiogroup', choices: ['Yes','No','Maybe','Never'], isRequired: true, name: 'Test_01', title: 'Do you like ice cream?' }],showQuestionNumbers: 'off'}";  
   json = JSON.stringify(json);
   model = new Model(json);

it dosen't recognise the json object when it have quotes on

 var json = "{ elements: [ {type: 'radiogroup', choices: ['Yes','No','Maybe','Never'], isRequired: true, name: 'Test_01', title: 'Do you like ice cream?' }],showQuestionNumbers: 'off'}";

it works when removes quotes

   json = { elements: [ {type: 'radiogroup', choices: ['Yes','No','Maybe','Never'], isRequired: true, name: 'Test_01', title: 'Do you like ice cream?' }],showQuestionNumbers: 'off'}; 

I have tried JSON.parse(json); it dosen't work, would anyone please suggest solution, please?

0

2 Answers 2

3

If you have JSON in a string, then you should do JSON.parse, not JSON.stringify.

Also, single quotes are invalid in JSON, so always use double-quotes for that.

// I fixed the JSON
var json = '{ elements: [ {type: "radiogroup", choices: ["Yes","No","Maybe","Never"], isRequired: true, name: "Test_01", title: "Do you like ice cream?" }],showQuestionNumbers: "off"}';
// The thing you would expect
var obj = JSON.parse(json);
Sign up to request clarification or add additional context in comments.

Comments

0

Because you are trying to stringify a string no the object remove " " and it would become object and then try JSON.stringify and JSON.parse is not working because the data is not in proper JSON string format. For example:

var object = '{"e":"a"}'; Then use JSON.parse(object); Which will convert your string in object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.