confusion about survey text #2322
-
Hello,
In the 'on_finish' function, 'sid' looks to me like JSON, so this may be an issue with me not knowing well enough how to parse JSON within JavaScript. In the console, the 'sid' object prints like this (I've tried to represent the indentation):
I've tried to get at Q0 with 'sid.response.Q0' and variants around that, but so far haven't succeeded. Any pointers here gratefully received! I'm using 6.3.0 btw; maybe I should upgrade to 7 (but I'm also using js-psychophysics which is compatible with 6.3.0 and I'm not sure it's been updated for 7). thanks as ever for jsPsych and thanks in advance for any help! Andrew |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @cainesap! You're very close. This line: var sid = jsPsych.data.get().filter({question_id: 'subjid'}).values()[0]; Is getting all of the jsPsych data, then filtering the trials based on the value of "question_id", then returning those trials as an array, and finally giving you the data object from the first (probably only?) trial in that array. So in other words it's giving you all of the data from that trial. Now what you need to do is access the "response" property from that trial data, and then access the specific question name ("Q0") within "response". So try this: var sid = jsPsych.data.get().filter({question_id: 'subjid'}).values()[0].response.Q0; Does that work for you? Btw you're right that certain types of data used to be stored as JSON strings in the jsPsych data, but then we switched to storing everything as objects/arrays rather than JSON. So with V6.3.0 I don't think you need the JSON parsing step. In earlier jsPsych versions you would need to parse the "response" with |
Beta Was this translation helpful? Give feedback.
Hi @cainesap! You're very close. This line:
Is getting all of the jsPsych data, then filtering the trials based on the value of "question_id", then returning those trials as an array, and finally giving you the data object from the first (probably only?) trial in that array. So in other words it's giving you all of the data from that trial. Now what you need to do is access the "response" property from that trial data, and then access the specific question name ("Q0") within "response". So try this:
Does that work for you?
Btw you'…