Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #31548

Re: String concat with JSON

Subject Re: String concat with JSON
Newsgroups comp.lang.javascript
References <4eKdnfDJCYfNS2fKnZ2dnUU7-YXNnZ2d@westnet.com.au>
From Andrew Poulos <ap_prog@hotmail.com>
Date 2016-10-10 10:47 +1100
Message-ID <4eKdnfPJCYexSmfKnZ2dnUU7-YWdnZ2d@westnet.com.au> (permalink)

Show all headers | View raw


On 10/10/2016 10:44 AM, Andrew Poulos wrote:
> I'm trying to communicate between the elearning piece I'm building and
> the learning management system (LMS).
>
> The elearning creates a separate JSON string for each section but the
> LMS stores them all in the same place in whatever order it decides is
> appropriate. To be able to identify them correctly I'm appending
> "Page_1=", "Page_2=", "Page_3="... to each JSON string. (I'm going to
> read back the entire string and then split it on "Page_x=" and then
> JSON.parse it.)
>
> With a simple test
>
> var tmp = JSON.stringify(currentPageData);
> // currentPageData is a one dim array with strings for elements
> LMSSetValue("cmi.comments", "Page_1=" + tmp);
>
> The LMS complains thus
>
> Exception:
> SyntaxError: Unexpected identifier at LMSSetValueMethod
>
> The relevant bits of the LMS code (over which I have no control) are
>
> setString = "this." + element + ".cmivalue =\"" + value + "\";";
> var result = eval(setString);
>
> It's trying to set value as "Page_1=["Test Data"]"
>
> Why does adding a string to a JSON string give me an invalid string?
>
> How do I get a valid string?

I just ran another test without adding the string

var tmp = JSON.stringify(currentPageData);
LMSSetValue("cmi.comments", tmp);

and it gives the same error with the value as "["Test Data"]"

Andrew Poulos

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

String concat with JSON Andrew Poulos <ap_prog@hotmail.com> - 2016-10-10 10:44 +1100
  Re: String concat with JSON Andrew Poulos <ap_prog@hotmail.com> - 2016-10-10 10:47 +1100
  Re: String concat with JSON Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-10-10 12:35 +0100

csiph-web