JSON string not recognised by LMS

A

Andrew Poulos

I'm creating a JSON string and passing it to a SCORM 1.2 compliant LMS thus:

var tmp = {};
tmp.assess = assessScore;
tmp.loc = location;
tmp.progress = notes.topics.toString();
fScormSetValue("cmi.suspend_data", tmp.toJSONString(), false);


alas the LMS complains with this error


Error: missing ; before statement

Line: 1104, Column: 35
Source Code:
this.cmi.suspend_data.cmivalue
= "{"assess":{"0_1q":true},"loc":"res_0_2.htm","progress":"1"}";
------^


Ok, the LMS sees the JSON string as more than one string. I can, though,
successfully read and write it to a cookie.

I'm not sure what's going on. How do I resolve this?

Andrew Poulos
 
A

Andrew Poulos

Randy said:
Andrew Poulos said the following on 12/18/2007 1:32 AM:

The first guess would that your problem is a quoting issue where it is
seeing the "{" and then assess and baulking on the quotes. Try changing
the outer quotes to ' and see if it makes a difference.

this.cmi.suspend_data.cmivalue='{"assess":{"0_1q":true},"loc":"res_0_2.htm","progress":"1"}';

The error is being produced/reported by the LMS and is not something I
can edit. I call fScormSetValue which tells the LMS to update
cmi.suspendata with the value tmp.toJSONString().

Andrew Poulos
 
A

Andrew Poulos

Andrew said:
The error is being produced/reported by the LMS and is not something I
can edit. I call fScormSetValue which tells the LMS to update
cmi.suspendata with the value tmp.toJSONString().
I just tried this
mphLMS.scormSetValue("cmi.suspend_data","'"+tmp.toJSONString()+"'",false);
in a wishful thinking frame of mind and got this error from the LMS:

Error: missing ; before statement

Line: 1104, Column: 36
Source Code:
this.cmi.suspend_data.cmivalue
="'{"assess":{"0_1q":true},"loc":"res_0_2.htm","progress":"1"}'";
------^

It looks like the LMS is wrapping the value I send in double quotes.

Andrew Poulos
 
A

Andrew Poulos

Randy said:
Andrew Poulos said the following on 12/18/2007 6:07 AM:

Then you either have to use ' in your value, escape it in your value, or
encode it.

If I first convert apostrophes to ' and then quote to apostrophes
the LMS doesn't complain:

var tmp = {};
tmp.assess = assessScore;
tmp.loc = location;
tmp.progress = notes.topics.toString();

var str = tmp.toJSONString();

str = str.replace(/'/g, "'");
str = str.replace(/\"/g, "'");

fScormSetValue("cmi.suspend_data", str, false);

When I read back the value I reverse the process. It seems to be
working. Is this the "best" way to do it?

Andrew Poulos
 
A

Andrew Poulos

Randy said:
Andrew Poulos said the following on 12/18/2007 8:53 PM:

Without knowing how the LMS works, nobody can tell you what way would be
"best". The only thing you can do is try different ways and see which
ones don't fail. If it isn't broke, don't fix it though :)
Alas the LMS is a 3rd party product and so not open to inspection.
Thanks for your help.

Andrew Poulos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top