상세 컨텐츠

본문 제목

json 튜토리얼 2 . 구조

카테고리 없음

by 동동주1123 2012. 2. 3. 16:49

본문


In this page you will learn about structures of JSON. you will also learn different forms of storing data in JSON.

(구조에 대해서 배울것이고 저장하는 여러 형식을 배울것이다) 

Data Structures supported by JSON(json이 지원하는 데이타구조)

JSON supports two widely used (amongst programming languages) data structures.
(널리사용되는 두가지 데이타 구조를 지원한다) 

A collection of name/value pairs. Different programming languages support this data structure in different names. Like object, record, struct, dictionary, hash table, keyed list, or associative array.

(이름/값의 컬렉션)
(다른 프로그래밍 언어들은 여러 가지의 이름으로 이를 지원한다, 객체,레코드,스트럿트,딕셔너리 등등) 

An ordered list of values. In various programming languages, it is called as array, vector, list, or sequence.
(값의 리스트 형식)
(배열,벡터,리스트,시퀀스등이라 불리운다) 

Since data structure supported by JSON is also supported by most of the modern programming languages, it makes JSON a very useful data-interchange format.
(JSON을 지원하면 여러 프로그램언어들로 부터 지원 받으므로 JSON은 가장 유용한 데이타 교환 형식이다) 

Data Types in JSON(json에서 데이타 타입)

JSON supports an array of data types. We will discuss those in detail in the following section of this page of the JSON tutorial.

(json은 데이터 형식의 배열을 지원하고 다음 섹션에서 자세히 설명한다) 

Object(객체)

Syntax(문법)

{ string : value, .......}

Explanation of Syntax(설명)

An object starts and ends with '{' and '}'. Between them, a number of string value pairs can reside. String and value is separated by a ':' and if there are more than one
string value pairs, they are separated by ','.

( 대괄호 {} 로 들어간다 . 그안에는 문자열값 쌍이 다수 들어간다)
( ':' 로 구분되고 두개 이상의 데이타라면 ',' 로 구분된다)
 

Example(예제)

{
"firstName": "Bidhan",
"lastName": "Chatterjee",
"age": 40,
"email":"bidhan@example.com"
}

In JSON, objects can nest arrays (starts and ends with '[' and ']') within it. The following example shows that.

(값안에 배열 넣을때는 [] 이용한다) 

{
"Students": [

{ "Name":"Amit Goenka" ,
"Major":"Physics" }, 
{ "Name":"Smita Pallod" ,
"Major":"Chemistry" }, 
{ "Name":"Rajeev Sen" , 
"Major":"Mathematics" }
]
}


Array(배열)

Syntax(문법)

[ value, .......]

Explanation of Syntax(문법설명)

An Array starts and ends with '[' and ']'. Between them, a number of values can reside. If there are more than one values reside, they are separated by ','.
( [] 이용해라)
 

Example

[100, 200, 300, 400]

If the JSON data describes an array, and each element of that array is an object.
(배열안에 각 객체가 요소로 들어간다) 

[
{
"name": "Bidhan Chatterjee",
"email": "bidhan@example.com"
},
{
"name": "Rameshwar Ghosh",
"email": "datasoftonline@example.com"
}
]

Remember that even arrays can also be nested within an object. The following shows that.

(배열도 객체내에서 중첩되어 나타날수 있다)

{
"firstName": "Bidhan",
"lastName": "Chatterjee",
"age": 40,
"address":
{
"streetAddress": "144 J B Hazra Road",
"city": "Burdwan",
"state": "Paschimbanga",
"postalCode": "713102"
},
"phoneNumber":
[
{
"type": "personal",
"number": "09832209761"
},
{
"type": "fax",
"number": "91-342-2567692"
}
]
}

Value(값)

Syntax(문법)

String || Number || Object || Array || TRUE || FALSE || NULL

A value can be a string, a number, an object, an Array, an Boolean value (i.e. true or false) or Null. This structure can be nested.
(값은 문자,숫자,객체,배열,불린,null이 될수 있다. 그리고 이구조는 중첩 가능하다)

String(문자열)

A string is a sequence of zero or more Unicode characters, enclosed by double quotes, using backslash escapes. A character is represented as a single character string, similar to a C or Java string.

(문자열은 백슬래시 탈출을 사용하여 따옴표로 둘러싸인 0 개 이상의 유니 코드 문자의 시퀀스입니다.성격은 C 또는 Java 문자열과 유사 하나의 문자열로 표시됩니다.) 

The following table shows supported string types.
(아래참고) 

String TypesDescription
" A double quotation mark.
\ Reverse Solidus
/ Solidus
b Backspace
f form feed
n newline
r Carriage return
t Horizontal tab
u Four hexadecimal digits

Number(숫자)

The following table shows supported number types.
(아래참고) 

Number TypesDescription
Integer Positive or negative Digits.1-9. And 0.
Fraction Fractions like .8.
Exponent e, e+, e-, E, E+, E-

Whitespace(공백)

Whitespace can be placed between any pair of supported data-types.

(공백은 지원되는 데이타타입 쌍 사이에 위치 할 수 있다)