Escape characters output by JSON Array?

Discussion in 'Java' started by laredotornado, Jul 14, 2008.

  1. Hi,

    I'm inserting some text on a JSF page using

    var treeModel = {identifier: 'id',label: 'label',
    items: <h:eek:utputText value='#{AddApplicationPage.applications}'
    escape='false'/>

    where the "getApplication" method returns the "toString()" method of a
    JSONArray object:

    JSONArray applications;
    /* applications var is populated */
    rtn = applications.toString().replaceAll("\"", "");
    return rtn;

    Problem is, if that object contains apostrophes, the Javascript above
    parses incorrectly. For example, here is an output block:

    var treeModel = {identifier: 'id',label: 'label',
    items: [{id: 'app8',label: 'DAVE_TEST',description: 'dave's
    test',loginURL: 'http://url1.com/login.html',logoutURL: 'http://
    url2.com/login.html?logout=true'}]
    };

    Any suggestions on a clean way to escape the apostraphes above?

    Thanks, - Dave
    laredotornado, Jul 14, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Adam Funk
    Replies:
    6
    Views:
    1,590
    Adam Funk
    Dec 2, 2011
  2. Florian Frank
    Replies:
    0
    Views:
    237
    Florian Frank
    Jun 30, 2009
  3. sajuptpm
    Replies:
    2
    Views:
    323
    sajuptpm
    Dec 28, 2012
  4. Acácio Centeno
    Replies:
    1
    Views:
    248
    dieter
    Feb 15, 2013
  5. Bryan Britten
    Replies:
    9
    Views:
    259
    Bryan Britten
    May 28, 2013
Loading...

Share This Page