JSON string not recognised by LMS

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Poulos

    JSON string not recognised by LMS

    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.to String();
    fScormSetValue( "cmi.suspend_da ta", tmp.toJSONStrin g(), false);


    alas the LMS complains with this error


    Error: missing ; before statement

    Line: 1104, Column: 35
    Source Code:
    this.cmi.suspen d_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
  • Randy Webb

    #2
    Re: JSON string not recognised by LMS

    Andrew Poulos said the following on 12/18/2007 1:32 AM:
    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.to String();
    fScormSetValue( "cmi.suspend_da ta", tmp.toJSONStrin g(), false);
    >
    >
    alas the LMS complains with this error
    >
    >
    Error: missing ; before statement
    >
    Line: 1104, Column: 35
    Source Code:
    this.cmi.suspen d_data.cmivalue
    = "{"assess":{"0_ 1q":true},"loc" :"res_0_2.htm", "progress":"1"} ";
    ------^
    The first guess would that your problem is a quoting issue where it is
    seeing the "{" and then assess and balking on the quotes. Try changing
    the outer quotes to ' and see if it makes a difference.

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

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

    Comment

    • Andrew Poulos

      #3
      Re: JSON string not recognised by LMS

      Randy Webb wrote:
      Andrew Poulos said the following on 12/18/2007 1:32 AM:
      >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.to String();
      >fScormSetValue ("cmi.suspend_d ata", tmp.toJSONStrin g(), false);
      >>
      >>
      >alas the LMS complains with this error
      >>
      >>
      >Error: missing ; before statement
      >>
      >Line: 1104, Column: 35
      >Source Code:
      >this.cmi.suspe nd_data.cmivalu e
      >= "{"assess":{"0_ 1q":true},"loc" :"res_0_2.htm", "progress":"1"} ";
      >------^
      >
      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.suspen d_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.toJSONStrin g().

      Andrew Poulos

      Comment

      • Andrew Poulos

        #4
        Re: JSON string not recognised by LMS

        Andrew Poulos wrote:
        Randy Webb wrote:
        >Andrew Poulos said the following on 12/18/2007 1:32 AM:
        >>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.progres s = notes.topics.to String();
        >>fScormSetValu e("cmi.suspend_ data", tmp.toJSONStrin g(), false);
        >>>
        >>>
        >>alas the LMS complains with this error
        >>>
        >>>
        >>Error: missing ; before statement
        >>>
        >>Line: 1104, Column: 35
        >>Source Code:
        >>this.cmi.susp end_data.cmival ue
        >>= "{"assess":{"0_ 1q":true},"loc" :"res_0_2.htm", "progress":"1"} ";
        >>------^
        >>
        >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.suspe nd_data.cmivalu e='{"assess":{" 0_1q":true},"lo c":"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.toJSONStrin g().
        >
        I just tried this
        mphLMS.scormSet Value("cmi.susp end_data","'"+t mp.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.suspen d_data.cmivalue
        ="'{"assess":{" 0_1q":true},"lo c":"res_0_2.htm ","progress":"1 "}'";
        ------^

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

        Andrew Poulos

        Comment

        • Randy Webb

          #5
          Re: JSON string not recognised by LMS

          Andrew Poulos said the following on 12/18/2007 6:07 AM:
          Andrew Poulos wrote:
          >Randy Webb wrote:
          >>Andrew Poulos said the following on 12/18/2007 1:32 AM:
          >>>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.progre ss = notes.topics.to String();
          >>>fScormSetVal ue("cmi.suspend _data", tmp.toJSONStrin g(), false);
          >>>>
          >>>>
          >>>alas the LMS complains with this error
          >>>>
          >>>>
          >>>Error: missing ; before statement
          >>>>
          >>>Line: 1104, Column: 35
          >>>Source Code:
          >>>this.cmi.sus pend_data.cmiva lue
          >>>= "{"assess":{"0_ 1q":true},"loc" :"res_0_2.htm", "progress":"1"} ";
          >>>------^
          >>>
          >>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.susp end_data.cmival ue='{"assess":{ "0_1q":true},"l oc":"res_0_2.ht m","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.suspenda ta with the value tmp.toJSONStrin g().
          >>
          I just tried this
          mphLMS.scormSet Value("cmi.susp end_data","'"+t mp.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.suspen d_data.cmivalue
          ="'{"assess":{" 0_1q":true},"lo c":"res_0_2.htm ","progress":"1 "}'";
          ------^
          >
          It looks like the LMS is wrapping the value I send in double quotes.
          Then you either have to use ' in your value, escape it in your value, or
          encode it.

          --
          Randy
          Chance Favors The Prepared Mind
          comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
          Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

          Comment

          • Andrew Poulos

            #6
            Re: JSON string not recognised by LMS

            Randy Webb wrote:
            Andrew Poulos said the following on 12/18/2007 6:07 AM:
            >Andrew Poulos wrote:
            >>Randy Webb wrote:
            >>>Andrew Poulos said the following on 12/18/2007 1:32 AM:
            >>>>I'm creating a JSON string and passing it to a SCORM 1.2 compliant
            >>>>LMS thus:
            >>>>>
            >>>>var tmp = {};
            >>>>tmp.asses s = assessScore;
            >>>>tmp.loc = location;
            >>>>tmp.progres s = notes.topics.to String();
            >>>>fScormSetVa lue("cmi.suspen d_data", tmp.toJSONStrin g(), false);
            >>>>>
            >>>>>
            >>>>alas the LMS complains with this error
            >>>>>
            >>>>>
            >>>>Error: missing ; before statement
            >>>>>
            >>>>Line: 1104, Column: 35
            >>>>Source Code:
            >>>>this.cmi.su spend_data.cmiv alue
            >>>>= "{"assess":{"0_ 1q":true},"loc" :"res_0_2.htm", "progress":"1"} ";
            >>>>------^
            >>>>
            >>>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.sus pend_data.cmiva lue='{"assess": {"0_1q":true}," loc":"res_0_2.h tm","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.suspendat a with the value tmp.toJSONStrin g().
            >>>
            >I just tried this
            >mphLMS.scormSe tValue("cmi.sus pend_data","'"+ tmp.toJSONStrin g()+"'",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.suspe nd_data.cmivalu e
            >="'{"assess":{ "0_1q":true},"l oc":"res_0_2.ht m","progress":" 1"}'";
            >------^
            >>
            >It looks like the LMS is wrapping the value I send in double quotes.
            >
            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.to String();

            var str = tmp.toJSONStrin g();

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

            fScormSetValue( "cmi.suspend_da ta", 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








            Comment

            • Randy Webb

              #7
              Re: JSON string not recognised by LMS

              Andrew Poulos said the following on 12/18/2007 8:53 PM:
              Randy Webb wrote:
              <snip>
              >Then you either have to use ' in your value, escape it in your value,
              >or encode it.
              >>
              >
              If I first convert apostrophes to &#39; and then quote to apostrophes
              the LMS doesn't complain:
              >
              var tmp = {};
              tmp.assess = assessScore;
              tmp.loc = location;
              tmp.progress = notes.topics.to String();
              >
              var str = tmp.toJSONStrin g();
              >
              str = str.replace(/'/g, "&#39;");
              str = str.replace(/\"/g, "'");
              >
              fScormSetValue( "cmi.suspend_da ta", 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?
              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 :)

              --
              Randy
              Chance Favors The Prepared Mind
              comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
              Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

              Comment

              • Andrew Poulos

                #8
                Re: JSON string not recognised by LMS

                Randy Webb wrote:
                Andrew Poulos said the following on 12/18/2007 8:53 PM:
                >Randy Webb wrote:
                >
                <snip>
                >
                >>Then you either have to use ' in your value, escape it in your value,
                >>or encode it.
                >>>
                >>
                >If I first convert apostrophes to &#39; and then quote to apostrophes
                >the LMS doesn't complain:
                >>
                >var tmp = {};
                >tmp.assess = assessScore;
                >tmp.loc = location;
                >tmp.progress = notes.topics.to String();
                >>
                >var str = tmp.toJSONStrin g();
                >>
                >str = str.replace(/'/g, "&#39;");
                >str = str.replace(/\"/g, "'");
                >>
                >fScormSetValue ("cmi.suspend_d ata", 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?
                >
                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

                Comment

                Working...