S
S
Spliff-Guru2015-03-10 13:27:25
JavaScript
Spliff-Guru, 2015-03-10 13:27:25

How to solve the problem with Cyrillic in JSON?

There is a draft page where the user:
1. selects the city, displaying the event plan
2. selects the time of the event in the event, displaying the description of the individual event
In paragraph 2, the formula is used:

...
newContent += times[loc][i].title.replace(/ /g, '-') + '">';
..

which loads the description of the event by the identifier obtained from the title element of the JSON file with the names of the events of the event (here: 3D modeling):
{
    "CA": [
        {
            "time": "9:00",
            "title": "3D-моделирование"
        },
...

looks for the corresponding identifier (i.e. 3D-моделирование) in the html file and displays the description on the page (in this case, it does not work, since the identifier is in Latin - Intro-to-3D-Modeling):
...
<div id="Intro-to-3D-Modeling">
      <h3>3D-моделирование</h3>
      <p>Описание</p>
    </div>
...

The problem is that if the text in the title elements in the JSON file is specified in Cyrillic, descriptions are not displayed. If in Latin - everything works. I can’t write JSON in Latin, since the same text is displayed on the web page. Naturally, I cannot write the values ​​of the id attributes in Cyrillic.
How to be?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Adamos, 2015-03-10
@Adamos

I didn't look at the attached file, but on the very issue I feel that you are doing nonsense.
Iterate over all h3s on the page, the one whose text matches your title - get the parent element. No id, and the text can be arbitrary.

A
Alexander Zachinalov, 2015-03-10
@SanDiesel

I do not welcome this method, but perhaps it will be more convenient for you to organize the output of information in a block that bears the name of the object

{
    "CA": [
        {
            "time": "9:00",
            "title": "3D-моделирование"
        },
...

<div id="CA">
      <h3>3D-моделирование</h3>
      <p>Описание</p>
    </div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question