Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

JSON methods, toJSON#186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tarasyyyk merged 9 commits intojavascript-tutorial:masterfromMykolaSopiha:json
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,7 @@

```js
let user = {
name: "John Smith",
name: "Іван Іванов",
age: 35
};

Expand Down
6 changes: 3 additions & 3 deletions1-js/05-data-types/12-json/1-serialize-object/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,13 +2,13 @@ importance: 5

---

#Turn the object intoJSONand back
#Перетворіть об’єкт вJSONі назад

Turn the`user`into JSON and then read it back into another variable.
Перетворіть`user`в JSON, а потім перетворіть його назад в іншу змінну.

```js
let user = {
name: "John Smith",
name: "Іван Іванов",
age: 35
};
```
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,8 +5,8 @@ let room = {
};

let meetup = {
title: "Conference",
occupiedBy: [{name: "John"}, {name: "Alice"}],
title: "Конференція",
occupiedBy: [{name: "Іван"}, {name: "Аліса"}],
place: room
};

Expand All@@ -19,12 +19,12 @@ alert( JSON.stringify(meetup, function replacer(key, value) {

/*
{
"title":"Conference",
"occupiedBy":[{"name":"John"},{"name":"Alice"}],
"title":"Конференція",
"occupiedBy":[{"name":"Іван"},{"name":"Аліса"}],
"place":{"number":23}
}
*/
```

Here we also need to test`key==""` to exclude the first call where it is normal that`value`is `meetup`.
Тут нам також потрібно перевірити`key==""`, щоб виключити перший виклик, де значення`value`рівне `meetup`.

22 changes: 11 additions & 11 deletions1-js/05-data-types/12-json/2-serialize-event-circular/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,39 +2,39 @@ importance: 5

---

#Exclude backreferences
#Виключити зворотні посилання

In simple cases of circular references, we can exclude an offending property from serialization by its name.
У простих випадках циклічних посиланнь ми можемо виключити від серіалізації властивість, через яку воно виникло, за її ім’ям.

But sometimes we can't just use the name, as it may be used both in circular references and normal properties. So we can check the property by its value.
Але іноді ми не можемо просто використовувати назву, оскільки вона може використовуватися як і у циклічних посиланнях, так і в нормальних властивостях. Таким чином, ми можемо перевірити властивість за її значенням.

Write`replacer` function to stringify everything, but remove properties that reference `meetup`:
Напишіть функцію`replacer`, щоб серіалізувати все, але видалити властивості, які посилаються на `meetup`:

```js run
let room = {
number: 23
};

let meetup = {
title: "Conference",
occupiedBy: [{name: "John"}, {name: "Alice"}],
title: "Конференція",
occupiedBy: [{name: "Іван"}, {name: "Аліса"}],
place: room
};

*!*
//circular references
//циклічне посилання
room.occupiedBy = meetup;
meetup.self = meetup;
*/!*

alert( JSON.stringify(meetup, function replacer(key, value) {
/*your code */
/*ваш код */
}));

/*result should be:
/*результат повинен бути:
{
"title":"Conference",
"occupiedBy":[{"name":"John"},{"name":"Alice"}],
"title":"Конференція",
"occupiedBy":[{"name":"Іван"},{"name":"Аліса"}],
"place":{"number":23}
}
*/
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp