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#197

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

Open
ImVietnam wants to merge8 commits intojavascript-tutorial:master
base:master
Choose a base branch
Loading
fromImVietnam:patch-22
Open
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
4 changes: 2 additions & 2 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,9 +2,9 @@ importance: 5

---

#Turn the object into JSONand back
#Biến đối tượng thành JSONvà ngược lại

Turn the`user`into JSONand then read it back into another variable.
Biến`user`thành JSONvà sau đó đọc lại thành một biến khác.

```js
let user = {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,5 +26,5 @@ alert( JSON.stringify(meetup, function replacer(key, value) {
*/
```

Here we also need to test`key==""`to exclude the first call where it is normal that `value`is `meetup`.
Ở đây, chúng ta cũng cần kiểm tra`key==""`để loại trừ cuộc gọi đầu tiên mà thông thường `value` `meetup`.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,13 +2,13 @@ importance: 5

---

#Exclude backreferences
#Loại trừ phản hồi

In simple cases of circular references, we can exclude an offending property from serialization by its name.
Trong các trường hợp đơn giản của tham chiếu vòng tròn, chúng ta có thể loại trừ một thuộc tính vi phạm khỏi việc tuần tự hóa theo tên của nó.

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.
Nhưng đôi khi chúng ta không thể chỉ sử dụng tên, vì nó có thể được sử dụng cả trong tham chiếu vòng và thuộc tính bình thường. Vì vậy, chúng ta có thể kiểm tra thuộc tính theo giá trị của nó.

Write`replacer`function to stringify everything, but remove properties that reference `meetup`:
Viết hàm`replacer`để xâu chuỗi mọi thứ, nhưng xóa các thuộc tính tham chiếu `meetup`:

```js run
let room = {
Expand All@@ -22,16 +22,16 @@ let meetup = {
};

*!*
//circular references
//tham chiếu vòng
room.occupiedBy = meetup;
meetup.self = meetup;
*/!*

alert( JSON.stringify(meetup, function replacer(key, value) {
/*your code */
/*mã của bạn */
}));

/*result should be:
/*kết quả nên là:
{
"title":"Conference",
"occupiedBy":[{"name":"John"},{"name":"Alice"}],
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp