@@ -50,6 +50,8 @@ msgid ""
5050"ambiguous. All values in Python are objects. In JSON, an object refers to "
5151"any data wrapped in curly braces, similar to a Python dictionary."
5252msgstr ""
53+ "在 Python 中處理 JSON 時,「物件」一詞的意義可能不明確。Python 中的所有值都是"
54+ "物件。在 JSON 中,物件指的是以大括號包住的任何資料,類似於 Python 字典。"
5355
5456#: ../../library/json.rst:27
5557msgid ""
@@ -247,6 +249,20 @@ msgid ""
247249">>> list(ComplexEncoder().iterencode(2 + 1j))\n"
248250"['[2.0', ', 1.0', ']']"
249251msgstr ""
252+ ">>> import json\n"
253+ ">>> class ComplexEncoder(json.JSONEncoder):\n"
254+ "... def default(self, obj):\n"
255+ "... if isinstance(obj, complex):\n"
256+ "... return [obj.real, obj.imag]\n"
257+ "... # 讓基底類別的預設方法引發 TypeError\n"
258+ "... return super().default(obj)\n"
259+ "...\n"
260+ ">>> json.dumps(2 + 1j, cls=ComplexEncoder)\n"
261+ "'[2.0, 1.0]'\n"
262+ ">>> ComplexEncoder().encode(2 + 1j)\n"
263+ "'[2.0, 1.0]'\n"
264+ ">>> list(ComplexEncoder().iterencode(2 + 1j))\n"
265+ "['[2.0', ', 1.0', ']']"
250266
251267#: ../../library/json.rst:124
252268msgid "Using :mod:`!json` from the shell to validate and pretty-print:"
@@ -332,13 +348,19 @@ msgid ""
332348"always produces :class:`str` objects, not :class:`bytes` objects, therefore "
333349"``fp.write()`` must support :class:`str` input."
334350msgstr ""
351+ "將 *obj* 序列化後寫入的類檔案物件。:mod:`!json` 模組總是產生 :class:`str` "
352+ "物件,而非 :class:`bytes` 物件,因此 ``fp.write()`` 必須支援 :class:`str` "
353+ "輸入。"
335354
336355#: ../../library/json.rst:178
337356msgid ""
338357"If ``True``, keys that are not of a basic type (:class:`str`, :class:`int`, :"
339358"class:`float`, :class:`bool`, ``None``) will be skipped instead of raising "
340359"a :exc:`TypeError`. Default ``False``."
341360msgstr ""
361+ "若為 ``True``,則會略過非基本型別(:class:`str`、:class:`int`、"
362+ ":class:`float`、:class:`bool`、``None``)的鍵,而非引發 "
363+ ":exc:`TypeError`。預設為 ``False``。"
342364
343365#: ../../library/json.rst:184
344366msgid ""
@@ -348,6 +370,9 @@ msgid ""
348370"quotation mark, reverse solidus, and the control characters U+0000 through "
349371"U+001F."
350372msgstr ""
373+ "若為 ``True``\\ (預設值),則保證輸出中所有輸入的非 ASCII 字元與不可列印字元"
374+ "都會被跳脫。若為 ``False``,則所有字元都會原樣輸出,但必須跳脫的字元除外:"
375+ "引號、反斜線,以及 U+0000 至 U+001F 的控制字元。"
351376
352377#: ../../library/json.rst:191
353378msgid ""
@@ -377,6 +402,9 @@ msgid ""
377402"overridden, for serializing into custom datatypes. If ``None`` (the "
378403"default), :class:`!JSONEncoder` is used."
379404msgstr ""
405+ "若有設定,則為覆寫了 :meth:`~JSONEncoder.default` 方法的自訂 JSON 編碼器,"
406+ "用於序列化為自訂資料型別。若為 ``None``\\ (預設值),則使用 "
407+ ":class:`!JSONEncoder`。"
380408
381409#: ../../library/json.rst:210
382410msgid ""
@@ -386,6 +414,9 @@ msgid ""
386414"level. If zero, negative, or ``\"\" `` (the empty string), only newlines are "
387415"inserted. If ``None`` (the default), no newlines are inserted."
388416msgstr ""
417+ "若為正整數或字串,則 JSON 陣列元素和物件成員會以該縮排層級美化輸出。正整數"
418+ "表示每層縮排的空格數;字串(例如 ``\"\\ t\" ``)則用於每層的縮排。若為零、負數或 "
419+ "``\"\" ``\\ (空字串),則只插入換行。若為 ``None``\\ (預設值),則不插入換行。"
389420
390421#: ../../library/json.rst:220
391422msgid ""
@@ -394,21 +425,26 @@ msgid ""
394425"``(',', ': ')`` otherwise. For the most compact JSON, specify ``(',', ':')`` "
395426"to eliminate whitespace."
396427msgstr ""
397- "一個二元組:``(item_separator, key_separator)``。如為 ``None``\\ (預設值)"
398- "則 *separators* 被預設為 ``(', ', ': ')``,否則預設為 ``(',', ': ')``。想要獲"
399- "得最緊湊的 JSON 表示形式,你可以指定 ``(',', ':')`` 來消除空格。"
428+ "一個二元組:``(item_separator, key_separator)``。若 *separators* 為 "
429+ "``None``\\ (預設值),則當 *indent* 為 ``None`` 時使用 ``(', ', ': ')``,"
430+ "否則使用 ``(',', ': ')``。若要獲得最緊湊的 JSON 表示形式,請指定 "
431+ "``(',', ':')`` 以消除空白字元。"
400432
401433#: ../../library/json.rst:229
402434msgid ""
403435"A function that is called for objects that can't otherwise be serialized. It "
404436"should return a JSON encodable version of the object or raise a :exc:"
405437"`TypeError`. If ``None`` (the default), :exc:`!TypeError` is raised."
406438msgstr ""
439+ "遇到無法以其他方式序列化的物件時會被呼叫的函式。它應回傳該物件可供 JSON 編碼"
440+ "的版本,或引發 :exc:`TypeError`。若為 ``None``\\ (預設值),則引發 "
441+ ":exc:`!TypeError`。"
407442
408443#: ../../library/json.rst:236
409444msgid ""
410445"If ``True``, dictionaries will be outputted sorted by key. Default ``False``."
411446msgstr ""
447+ "若為 ``True``,則字典會依鍵排序後輸出。預設為 ``False``。"
412448
413449#: ../../library/json.rst:242
414450msgid ""
@@ -432,7 +468,7 @@ msgstr "除了整數之外,*indent* 還允許使用字串作為輸入。"
432468
433469#: ../../library/json.rst:253 ../../library/json.rst:536
434470msgid "Use ``(',', ': ')`` as default if *indent* is not ``None``."
435- msgstr "如果 *indent* 不是 ``None``,則使用 ``(',', ': ')`` 作為預設值"
471+ msgstr "如果 *indent* 不是 ``None``,則使用 ``(',', ': ')`` 作為預設值。 "
436472
437473#: ../../library/json.rst:256 ../../library/json.rst:346
438474msgid ""
@@ -462,13 +498,17 @@ msgid ""
462498"A ``.read()``-supporting :term:`text file` or :term:`binary file` containing "
463499"the JSON document to be deserialized."
464500msgstr ""
501+ "支援 ``.read()`` 且包含待去序列化 JSON 文件的\\ :term:`文字檔案 <text file>`"
502+ "\\ 或\\ :term:`二進位檔案 <binary file>`。"
465503
466504#: ../../library/json.rst:281
467505msgid ""
468506"If set, a custom JSON decoder. Additional keyword arguments to :func:`!load` "
469507"will be passed to the constructor of *cls*. If ``None`` (the default), :"
470508"class:`!JSONDecoder` is used."
471509msgstr ""
510+ "若有設定,則為自訂 JSON 解碼器。傳給 :func:`!load` 的額外關鍵字引數會傳遞給 "
511+ "*cls* 的建構子。若為 ``None``\\ (預設值),則使用 :class:`!JSONDecoder`。"
472512
473513#: ../../library/json.rst:288
474514msgid ""
@@ -528,6 +568,7 @@ msgstr ""
528568#: ../../library/json.rst:0
529569msgid "Raises"
530570msgstr ""
571+ "引發"
531572
532573#: ../../library/json.rst:332
533574msgid "When the data being deserialized is not a valid JSON document."
@@ -700,6 +741,9 @@ msgid ""
700741"`dict`. This feature can be used to implement custom decoders. If "
701742"*object_hook* is also defined, the *object_pairs_hook* takes priority."
702743msgstr ""
744+ "*object_pairs_hook* 是一個可選函式,會以每個 JSON 物件解碼後的有序對串列作為"
745+ "引數來呼叫它。*object_pairs_hook* 的回傳值將用來取代 :class:`dict`。此功能"
746+ "可用於實作自訂解碼器。若也定義了 *object_hook*,則 *object_pairs_hook* 優先。"
703747
704748#: ../../library/json.rst:416
705749msgid "Added support for *object_pairs_hook*."
@@ -1146,6 +1190,16 @@ msgid ""
11461190">>> json.loads('NaN')\n"
11471191"nan"
11481192msgstr ""
1193+ ">>> # 這兩次呼叫都不會引發例外,但結果不是有效的 JSON\n"
1194+ ">>> json.dumps(float('-inf'))\n"
1195+ "'-Infinity'\n"
1196+ ">>> json.dumps(float('nan'))\n"
1197+ "'NaN'\n"
1198+ ">>> # 去序列化時亦同\n"
1199+ ">>> json.loads('-Infinity')\n"
1200+ "-inf\n"
1201+ ">>> json.loads('NaN')\n"
1202+ "nan"
11491203
11501204#: ../../library/json.rst:682
11511205msgid ""
@@ -1270,6 +1324,8 @@ msgid ""
12701324"validate and pretty-print JSON objects. The :mod:`!json.tool` submodule "
12711325"implements this interface."
12721326msgstr ""
1327+ "可以透過 ``python -m json`` 將 :mod:`!json` 模組當作腳本呼叫,以驗證並美化"
1328+ "輸出 JSON 物件。:mod:`!json.tool` 子模組實作了此介面。"
12731329
12741330#: ../../library/json.rst:755
12751331msgid ""
@@ -1309,6 +1365,8 @@ msgid ""
13091365"For backwards compatibility, invoking the CLI as ``python -m json.tool`` "
13101366"remains supported."
13111367msgstr ""
1368+ "現在可以透過 ``python -m json`` 直接執行 :mod:`!json` 模組。為了維持向後相容"
1369+ "性,仍支援透過 ``python -m json.tool`` 呼叫命令列介面。"
13121370
13131371#: ../../library/json.rst:779
13141372msgid "Command-line options"
0 commit comments