Difference between revisions of "JSON/pl"

From Lazarus wiki
Jump to navigationJump to search
(→‎Overview: tłumaczenie na j. polski)
(→‎JSON Object: tłumaczenie na j. polski)
Line 6: Line 6:
 
W porównaniu z [[XML]], jest bardziej czytelny dla człowieka.
 
W porównaniu z [[XML]], jest bardziej czytelny dla człowieka.
  
== JSON Object ==
+
== Obiekt JSON ==
A JSON Object is nothing more than a collection of comma-separated name/value pairs (often called members) enclosed in curly brackets:
+
Obiekt JSON to nic innego jak zbiór oddzielonych przecinkami par nazwa/wartość (często nazywanych elementami) ujętych w nawiasy klamrowe:
  
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
Line 13: Line 13:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
To make it easier for humans to read and visualize, the name/value pairs are often listed vertically:
+
Aby ułatwić ludziom czytanie i wizualizację, par nazwa/wartość są one często wymienione pionowo:
  
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
Line 21: Line 21:
 
}</syntaxhighlight>
 
}</syntaxhighlight>
  
The name is supposed to be a string in double quotes, while the value can be any of the following:
+
Nazwa jest łańcuchem znaków ujętych w podwójnych cudzysłowach, a wartością może być jedna z następujących opcji:
  
* a simple string, numeric, boolean or null value (strings are enclosed in double quotes):<br /><code>{"id":1, "name":"John Doe", "married":false}</code>
+
* prosty ciąg, wartość liczbowa, logiczna lub null (ciągi są ujęte w podwójne cudzysłowy):<br /><code>{"id":1, "name":"John Doe", "married":false}</code>
  
* an array; which is a collection of comma-separated values in square brackets:<br /><code>{"primeNumbers":[2, 3, 5, 7, 11, 13, 17], "oddNumbers":[1,3,5,7]}</code>
+
* tablica; który jest zbiorem wartości oddzielonych przecinkami w nawiasach kwadratowych:<br /><code>{"primeNumbers":[2, 3, 5, 7, 11, 13, 17], "oddNumbers":[1,3,5,7]}</code>
  
* an object; which is a collection of name:value pairs enclosed in curly brackets:<br /><code>{"address":{"street":"145 Koinange Street", "City":"Nairobi", "Country":"Kenya"}}</code>
+
* obiekt; który jest zbiorem par nazwa/wartość zawartych w nawiasach klamrowych:<br /><code>{"address":{"street":"145 Koinange Street", "City":"Nairobi", "Country":"Kenya"}}</code>
  
 
+
Obiekty JSON można zawsze zagnieżdżać dowolnie, aby tworzyć jeszcze bardziej złożone obiekty:
JSON objects can always be nested arbitrarily to create even more complex objects:
 
  
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
Line 42: Line 41:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Check this [[fcl-json#Traversing Items|link]] for extracting the information when you have several users.
+
Sprawdź ten [[fcl-json#Traversing Items|link]], aby wyodrębnić informacje, gdy masz kilku użytkowników.
  
 
== Valid JSON format ==
 
== Valid JSON format ==

Revision as of 22:14, 3 June 2020

English (en) suomi (fi) 日本語 (ja) 한국어 (ko) polski (pl) русский (ru) 中文(中国大陆)‎ (zh_CN)

Przegląd

JSON (JavaScript Object Notation) jest to znormalizowany format wymiany danych zapisanych przy użyciu prostego tekstu. Jak sama nazwa wskazuje, jest oparty na podstawie języka programowania JavaScript; jest jednak całkowicie niezależny od języka. Oprócz tego, że ludzie mogą go łatwo czytać i pisać pliki JSON, to maszyny również są w stanie parsować i generować te pliki.

W porównaniu z XML, jest bardziej czytelny dla człowieka.

Obiekt JSON

Obiekt JSON to nic innego jak zbiór oddzielonych przecinkami par nazwa/wartość (często nazywanych elementami) ujętych w nawiasy klamrowe:

{"name1":value1, "name2":value2 ...}

Aby ułatwić ludziom czytanie i wizualizację, par nazwa/wartość są one często wymienione pionowo:

{
	"name1": value1,
	"name2": value2
}

Nazwa jest łańcuchem znaków ujętych w podwójnych cudzysłowach, a wartością może być jedna z następujących opcji:

  • prosty ciąg, wartość liczbowa, logiczna lub null (ciągi są ujęte w podwójne cudzysłowy):
    {"id":1, "name":"John Doe", "married":false}
  • tablica; który jest zbiorem wartości oddzielonych przecinkami w nawiasach kwadratowych:
    {"primeNumbers":[2, 3, 5, 7, 11, 13, 17], "oddNumbers":[1,3,5,7]}
  • obiekt; który jest zbiorem par nazwa/wartość zawartych w nawiasach klamrowych:
    {"address":{"street":"145 Koinange Street", "City":"Nairobi", "Country":"Kenya"}}

Obiekty JSON można zawsze zagnieżdżać dowolnie, aby tworzyć jeszcze bardziej złożone obiekty:

{"user":
	{	"userid": 1900,
		"username": "jsmith",
		"password": "secret",
		"groups": [ "admins", "users", "maintainers"]
	}
}

Sprawdź ten link, aby wyodrębnić informacje, gdy masz kilku użytkowników.

Valid JSON format

There are a few rules and guidelines that define the JSON syntax (see RFC 4627):

  • JSON objects are encapsulated within opening and closing brackets { }. An empty object can be represented by { }
  • Arrays are encapsulated within opening and closing square brackets [ ]. An empty array can be represented by [ ]
  • A member is represented by a key-value pair
  • The key of a member should be contained in double quotes
  • Each member SHOULD have a unique key within an object structure
  • The value of a member must be contained in double quotes if it is a string
  • Boolean values are represented using the true or false literals in lower case
  • Number values are represented using double-precision floating-point format; Scientific notation is supported; Numbers should not have leading zeroes
  • "Offensive" characters in a string need to be escaped using the backslash character
  • Null values are represented by the null literal in lower case
  • Other object types, such as dates, are not natively supported and should be converted to strings; to be managed by the parser/client
  • Each member of an object or each array value must be followed by a comma if it is not the last one
  • The common extension for json files is .json
  • The MIME type for json files is application/json

Implementations

JSON implementation is not very strict, and a lot of leeway is granted to the client application and/or parser to enforce the guidelines. As usual when writing code:

  • be liberal in what you accept
  • be strict (adhering to the standard) in what you send.

There are two main implementations of JSON:

The official JSON Specification syntax

This implementation adheres strictly to the RFC 4627 guidelines above and does not allow deviation from the specification.

The Javascript syntax

This implementation follows the implementation of the Javascript programming language and as such allows for a few deviations from the official specification. For example:

  1. allows un-quoted keys eg {name: "John Doe" }
  2. allows single quotes for keys and/or string values; and a liberal mix of single and double quotes eg {'name': "John Doe", "language":'Pascal'}
  3. allows trailing comma after the last member of an array and/or object eg {"keywords":["if","begin","for",], "IDEs":["Lazarus","fpIDE","MSEide"],}

See also

[[:{{{NameWithoutSuffix}}}/ru|한국어 (ru)]]