Skip to content

1 js/05 data types/11 json#79

Merged
leviding merged 12 commits intojavascript-tutorial:zh-hansfrom
sunhaokk:1-js/05-data-types/11-json
May 7, 2018
Merged

1 js/05 data types/11 json#79
leviding merged 12 commits intojavascript-tutorial:zh-hansfrom
sunhaokk:1-js/05-data-types/11-json

Conversation

@sunhaokk
Copy link
Copy Markdown
Contributor

@sunhaokk sunhaokk commented May 3, 2018

resolve #67
@leviding 翻译完毕

@Starriers
Copy link
Copy Markdown
Contributor

Starriers commented May 5, 2018

@leviding 校对认领

@leviding
Copy link
Copy Markdown
Member

leviding commented May 5, 2018

@Starriers ok

Copy link
Copy Markdown
Contributor

@Starriers Starriers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sunhaokk @leviding 校对完成

Comment thread 1-js/05-data-types/11-json/article.md Outdated
@@ -1,10 +1,10 @@
# JSON methods, toJSON
# JSON 方法和 toJSON
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该不是和 的关系,指的就是后面的

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON 方法和 toJSON
=>
JSON 方法,toJSON

当然,这样的字符串应该包含所有重要的属性。

We could implement the conversion like this:
我们可以像这样实现转换:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

发送=>转发

Comment thread 1-js/05-data-types/11-json/article.md Outdated

...But in the process of development, new properties are added, old properties are renamed and removed. Updating such `toString` every time can become a pain. We could try to loop over properties in it, but what if the object is complex and has nested objects in properties? We'd need to implement their conversion as well. And, if we're sending the object over a network, then we also need to supply the code to "read" our object on the receiving side.
...但在开发过程中,新增了一些属性,旧的属性被重命名并删除。每次更新这种 `toString` 都会变得很痛苦。 我们可以尝试循环其中的属性,
但是如果对象很复杂,并且在属性中嵌套对象呢?我们也需要对他们进行转换。如,如果我们通过网络发送对象,那么我们还需要提供代码来在接收端“读取”我们的对象。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多空了一行

Comment thread 1-js/05-data-types/11-json/article.md Outdated

...But in the process of development, new properties are added, old properties are renamed and removed. Updating such `toString` every time can become a pain. We could try to loop over properties in it, but what if the object is complex and has nested objects in properties? We'd need to implement their conversion as well. And, if we're sending the object over a network, then we also need to supply the code to "read" our object on the receiving side.
...但在开发过程中,新增了一些属性,旧的属性被重命名并删除。每次更新这种 `toString` 都会变得很痛苦。 我们可以尝试循环其中的属性,
但是如果对象很复杂,并且在属性中嵌套对象呢?我们也需要对他们进行转换。如,如果我们通过网络发送对象,那么我们还需要提供代码来在接收端“读取”我们的对象。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

它们

Comment thread 1-js/05-data-types/11-json/article.md Outdated
## JSON.stringify

The [JSON](http://en.wikipedia.org/wiki/JSON) (JavaScript Object Notation) is a general format to represent values and objects. It is described as in [RFC 4627](http://tools.ietf.org/html/rfc4627) standard. Initially it was made for JavaScript, but many other languages have libraries to handle it as well. So it's easy to use JSON for data exchange when the client uses JavaScript and the server is written on Ruby/PHP/Java/Whatever.
[JSON](http://en.wikipedia.org/wiki/JSON) (JavaScript Object Notation) 是表示值和对象的通用格式。它被描述为 [RFC 4627](http://tools.ietf.org/html/rfc4627)标准。最初它是为 JavaScript 编写的,但许多其他语言也有库来处理它。因此,当客户端使用 JavaScript 并且服务器使用 Ruby/PHP/Java/Whatever 编写时,使用 JSON 进行数据交换非常容易。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

标准前 空格

Comment thread 1-js/05-data-types/11-json/article.md Outdated
```

...And now we need to *deserialize* it, to turn back into JavaScript object.
...现在我们需要 **反序列化它**,重新转换成 JavaScript 对象。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要后不用空格

Comment thread 1-js/05-data-types/11-json/article.md Outdated
`meetup.date` 的值是一个字符串,而不是 `Date` 对象。 `JSON.parse` 如何知道它应该将该字符串转换为 `Date`

Let's pass to `JSON.parse` the reviving function that returns all values "as is", but `date` will become a `Date`:
让我们传递返回所有值的函数给 `JSON.parse`,但 `date` 将变成了 `Date`,正常运行:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

后面一个逗号

Comment thread 1-js/05-data-types/11-json/article.md Outdated
- If an object has `toJSON`, then it is called by `JSON.stringify`.
- JSON 是一种数据格式,对于大多数编程语言都有自己的独立标准和库。
- JSON 支持 objectsarraysstringsnumbersbooleans `null`
- JavaScript 提供序列化成 JSON 方法 [JSON.stringify](mdn:js/JSON/stringify)和解析 JSON 方法 [JSON.parse](mdn:js/JSON/parse)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

的方法

Comment thread 1-js/05-data-types/11-json/article.md Outdated
...现在我们需要 **反序列化它**,重新转换成 JavaScript 对象。

Let's do it by calling `JSON.parse`:
让我们通过调用 `JSON.parse` 来完成:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

冒号

Comment thread 1-js/05-data-types/11-json/article.md Outdated
## JSON.parse

To decode a JSON-string, we need another method named [JSON.parse](mdn:js/JSON/parse).
要解码 JSON 字符串,我们需要另一个方法 [JSON.parse](mdn:js/JSON/parse).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

句号

@jasonxia23
Copy link
Copy Markdown

@leviding 认领校对

@leviding
Copy link
Copy Markdown
Member

leviding commented May 5, 2018

@jasonxia23 ok

Copy link
Copy Markdown

@jasonxia23 jasonxia23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leviding 校对完成
@sunhaokk 有些地方有点口语化了哈

```

Here we also need to test `key==""` to exclude the first call where it is normal that `value` is `meetup`.
这里我们也需要测试 `key==""` 在正常情况下排除第一个调用 `value` `meetup`
Copy link
Copy Markdown

@jasonxia23 jasonxia23 May 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里我们也需要测试 key=="" 在正常情况下排除第一个调用 valuemeetup
=>
这里我们也需要判断 key=="" 以排除第一个调用时 valuemeetup 的情况。

Comment thread 1-js/05-data-types/11-json/article.md Outdated
@@ -1,10 +1,10 @@
# JSON methods, toJSON
# JSON 方法和 toJSON
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON 方法和 toJSON
=>
JSON 方法,toJSON

Comment thread 1-js/05-data-types/11-json/article.md Outdated
```

...But in the process of development, new properties are added, old properties are renamed and removed. Updating such `toString` every time can become a pain. We could try to loop over properties in it, but what if the object is complex and has nested objects in properties? We'd need to implement their conversion as well. And, if we're sending the object over a network, then we also need to supply the code to "read" our object on the receiving side.
...但在开发过程中,新增了一些属性,旧的属性被重命名并删除。每次更新这种 `toString` 都会变得很痛苦。 我们可以尝试循环其中的属性,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

。 我们
=>
。我们
多了个空格

Comment thread 1-js/05-data-types/11-json/article.md Outdated
```

...But in the process of development, new properties are added, old properties are renamed and removed. Updating such `toString` every time can become a pain. We could try to loop over properties in it, but what if the object is complex and has nested objects in properties? We'd need to implement their conversion as well. And, if we're sending the object over a network, then we also need to supply the code to "read" our object on the receiving side.
...但在开发过程中,新增了一些属性,旧的属性被重命名并删除。每次更新这种 `toString` 都会变得很痛苦。 我们可以尝试循环其中的属性,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

循环
=>
遍历

Comment thread 1-js/05-data-types/11-json/article.md Outdated
## JSON.stringify

The [JSON](http://en.wikipedia.org/wiki/JSON) (JavaScript Object Notation) is a general format to represent values and objects. It is described as in [RFC 4627](http://tools.ietf.org/html/rfc4627) standard. Initially it was made for JavaScript, but many other languages have libraries to handle it as well. So it's easy to use JSON for data exchange when the client uses JavaScript and the server is written on Ruby/PHP/Java/Whatever.
[JSON](http://en.wikipedia.org/wiki/JSON) (JavaScript Object Notation) 是表示值和对象的通用格式。它被描述为 [RFC 4627](http://tools.ietf.org/html/rfc4627)标准。最初它是为 JavaScript 编写的,但许多其他语言也有库来处理它。因此,当客户端使用 JavaScript 并且服务器使用 Ruby/PHP/Java/Whatever 编写时,使用 JSON 进行数据交换非常容易。
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

并且服务器使用
=>
而服务器使用
这里的并列语气没有那么强烈,用而感觉更顺口

Comment thread 1-js/05-data-types/11-json/article.md Outdated
第一个调用很特别。它是使用特殊的“包装对象”制作的: `{"": meetup}`。换句话说,第一个 `(key,value)` 对是空键,并且该值是整个目标对象。这就是为什么上面的例子中第一行是 `":[object Object]"` 的原因。

The idea is to provide as much power for `replacer` as possible: it has a chance to analyze and replace/skip the whole object if necessary.
基于这个理念为 `replacer` 提供了更强大的功能: 如有必要,它有机会分析和替换/跳过整个对象。
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: 如有必要
=>
:如有必要

Comment thread 1-js/05-data-types/11-json/article.md Outdated
在这里我们可以看到 `date` `(1)` 变成了一个字符串。这是因为所有日期都有一个内置的 `toJSON` 方法来返回这种类型的字符串。

Now let's add a custom `toJSON` for our object `room`:
现在让我们为对象 `room` 添加一个自定义的 `toJSON`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删掉“:”后面多出来的空格

Comment thread 1-js/05-data-types/11-json/article.md Outdated
## JSON.parse

To decode a JSON-string, we need another method named [JSON.parse](mdn:js/JSON/parse).
要解码 JSON 字符串,我们需要另一个方法 [JSON.parse](mdn:js/JSON/parse).
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原翻译更好,不一定要严格遵循原文

Comment thread 1-js/05-data-types/11-json/article.md Outdated
此外,JSON 不支持注释。向 JSON 添加注释无效。

There's another format named [JSON5](http://json5.org/), which allows unquoted keys, comments etc. But this is a standalone library, not in the specification of the language.
还有另一种名为 [JSON5](http://json5.org/)的格式,它允许未加引号的键,注释等。但这是一个独立的库,不在该语言的规范中。
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

未加引号的键,注释
=>
未加引号的键、注释

Comment thread 1-js/05-data-types/11-json/article.md Outdated
哇!报错了!

The value of `meetup.date` is a string, not a `Date` object. How could `JSON.parse` know that it should transform that string into a `Date`?
`meetup.date` 的值是一个字符串,而不是 `Date` 对象。 `JSON.parse` 如何知道它应该将该字符串转换为 `Date`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

而不是 Date 对象。
后面的空格

@leviding
Copy link
Copy Markdown
Member

leviding commented May 6, 2018

@sunhaokk 可以修改啦

@sunhaokk
Copy link
Copy Markdown
Contributor Author

sunhaokk commented May 7, 2018

@Starriers @jasonxia23 感谢指导
@leviding 修改完成

@leviding
Copy link
Copy Markdown
Member

leviding commented May 7, 2018

@sunhaokk 对应文件夹有五个 MarkDown 文件,还有几个需要继续翻一下

@leviding leviding added the WIP Work in process label May 7, 2018
@sunhaokk
Copy link
Copy Markdown
Contributor Author

sunhaokk commented May 7, 2018

@leviding
一共五个md
其中两个task.md都带importance: 5 没敢翻译。
剩下的一个solution.md没有需要翻译的字段。
最后一个solution.md 就一句话 已经翻译提交。

@leviding
Copy link
Copy Markdown
Member

leviding commented May 7, 2018

@sunhaokk importance 不翻译是指这个字段不翻译,这一句保留不翻译。但是文件的其他内容需要翻译。请把两个 task 文件翻译提交上来。

@leviding leviding merged commit 234f4ba into javascript-tutorial:zh-hans May 7, 2018
@leviding leviding added 翻译完成 and removed WIP Work in process 正在校对 labels May 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants