How do i modified the JSON of result?
Before
After
I can obtain the result but the result json string is {"xxx" : "yyy"}
I want to change the json string to [{"questiono" : "xxx" , "answerno": "yyy"}}
I did look the ways of changing it but dunno how the survey library works for the result data.
You can precess survey result JSON in the onComplete handler:
onComplete
JavaScriptsurvey .onComplete .add(function (result) { var modifiedData = Object.keys(result.data).map(function(qName) { return { questionNo: qName, answerNo: result.data[qName] } }); document .querySelector('#surveyResult') .innerHTML = "result: " + JSON.stringify(modifiedData); });
survey .onComplete .add(function (result) { var modifiedData = Object.keys(result.data).map(function(qName) { return { questionNo: qName, answerNo: result.data[qName] } }); document .querySelector('#surveyResult') .innerHTML = "result: " + JSON.stringify(modifiedData); });
Here is the example - https://plnkr.co/edit/VMEs1QlqJeros8nXGWNn?p=preview
I can obtain the result but the result json string is {"xxx" : "yyy"}
I want to change the json string to [{"questiono" : "xxx" , "answerno": "yyy"}}
I did look the ways of changing it but dunno how the survey library works for the result data.
You can precess survey result JSON in the
onComplete
handler:survey .onComplete .add(function (result) { var modifiedData = Object.keys(result.data).map(function(qName) { return { questionNo: qName, answerNo: result.data[qName] } }); document .querySelector('#surveyResult') .innerHTML = "result: " + JSON.stringify(modifiedData); });
Here is the example - https://plnkr.co/edit/VMEs1QlqJeros8nXGWNn?p=preview