2

What is the proper syntax to display 25' as output description?

Example:

var sizeData = [            
    {description:'Recommended sizes listed below', value:'', text:'Select Size'},                   
    {description:'Boat < 25 &prime;, value:'size0', text:'Size 0'},
    {description:'25-35 Foot Boat', value:'size2', text:'Size 2'},
    {description:'40-45 Foot Boat', value:'size3', text:'Size 3'},
];
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Casey Jardin
  • 21
  • 1
  • 4

4 Answers4

3

In a JSON file, where all strings are delimited with double quotes, you can just write apostrophes.

In a JavaScript object literal, where you can delimit strings with apostrophes as well, you then will need to escape them with a backslash: '\'' (dobule quote delimiters: just "'").

The prime symbol - which is different from the apostrophe you typed - can be inserted without harm. Depending on the encoding of your file, you might need to write it a bit different. In HTML you can replace it with the entity &prime;, in both JSON and JavaScript you can replace it with the escape sequence \u2032 if you do not want to use the recommended UTF-8 character .

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • To be clear, escaping is needed *if* you chose to use the single-quotes for that value... if using the double quotes there is no need for escaping the single quote within. – Lawrence Dol Jan 17 '13 at 01:16
  • It should be noted that in JSON the keys should be enclosed in double quotes too. – bfavaretto Jan 17 '13 at 01:18
  • @bfavaretto: Since in JSON keys *are* strings, the same rules apply to them – Bergi Jan 17 '13 at 01:24
2

Like so:

foo: '25′'

Notice that the prime character and the apostrophe character are two different Unicode characters. You can put the prime character inside a single-quote encapsulated string normally.

Btw, above the prime character is printed in monospace font. This is how it looks in sans-serif:

25′, and 25′′

Šime Vidas
  • 182,163
  • 62
  • 281
  • 385
0

var sizeData = [
{description:\'Recommended sizes listed below\', value:\'\', text:\'Select Size\'},
{description:\'Boat < 25 ′, value:\'size0\', text:\'Size 0\'} ];

Colin
  • 11
  • 1
0

You can enclose a (') using a "". Basically like this " ' ".

Ripspace
  • 551
  • 6
  • 21