고요빛물결
RESTful

Restful에서 리턴되는 JSON 값

· 2021-01-19 (화) 00:17:59 · 1316

제일 앞에 나오는 값이 단수라면 뒤에는 object가.

복수라면 object의 array가..

 

Single Article 인경우

[code]

{
  "article": {
    "slug": "how-to-train-your-dragon",
    "title": "How to train your dragon",
    "description": "Ever wonder how?",
    "body": "It takes a Jacobian",
    "tagList": ["dragons", "training"],
    "createdAt": "2016-02-18T03:22:56.637Z",
    "updatedAt": "2016-02-18T03:48:35.824Z",
    "favorited": false,
    "favoritesCount": 0,
    "author": {
      "username": "jake",
      "bio": "I work at statefarm",
      "image": "https://i.stack.imgur.com/xHWG8.jpg",
      "following": false
    }
  }
}

[/code]

 

Multiple Article인경우

[code]

{
  "articles":[{
    "slug": "how-to-train-your-dragon",
    "title": "How to train your dragon",
    "description": "Ever wonder how?",
    "body": "It takes a Jacobian",
    "tagList": ["dragons", "training"],
    "createdAt": "2016-02-18T03:22:56.637Z",
    "updatedAt": "2016-02-18T03:48:35.824Z",
    "favorited": false,
    "favoritesCount": 0,
    "author": {
      "username": "jake",
      "bio": "I work at statefarm",
      "image": "https://i.stack.imgur.com/xHWG8.jpg",
      "following": false
    }
  }, {
    "slug": "how-to-train-your-dragon-2",
    "title": "How to train your dragon 2",
    "description": "So toothless",
    "body": "It a dragon",
    "tagList": ["dragons", "training"],
    "createdAt": "2016-02-18T03:22:56.637Z",
    "updatedAt": "2016-02-18T03:48:35.824Z",
    "favorited": false,
    "favoritesCount": 0,
    "member": {
      "mbId": "jake",
      "bio": "I work at statefarm",
      "image": "https://i.stack.imgur.com/xHWG8.jpg",
      "following": false
    }
  }, {
  }, {
  }],
  "articlesCount": 200
  "links": [ 
    "/api\/v1\/board\/free?page=2&per_page=20>; rel=\"next\"", 
    "/api\/v1\/board\/free?page=10&per_page=20>; rel=\"last\""
}

[/code]

 

당연한 것 같지만, 대략 이런 구조가 되겠네요.

 

article.subject와

 

배열은 보통 forEach로 articles를 article로 매핑해서 각각을 사용하면 되는 것 같습니다.

댓글을 작성하시려면 로그인이 필요합니다.

소모임

23,243건
+
분류 제목 글쓴이 날짜 조회
해외사용자 21-01-22 조회 1,537
해외사용자
[해외사용자]
21-01-22 조회 1,619
RESTful 21-01-22 조회 1,306
RESTful 21-01-22 조회 1,586
RESTful 21-01-21 조회 1,487
RESTful 21-01-21 조회 1,272
모형취미 21-01-20 조회 2,154
RESTful 21-01-20 조회 1,313
해외사용자 21-01-19 조회 1,822
RESTful 21-01-19 조회 1,354
RESTful 21-01-19 조회 1,317
RESTful 21-01-18 조회 1,086
RESTful 21-01-17 조회 1,546
RESTful 21-01-17 조회 1,638
PHP프레임워크 21-01-17 조회 2,604
RESTful 21-01-16 조회 2,079
RESTful 21-01-16 조회 2,153
RESTful 21-01-16 조회 1,219
해외사용자 21-01-16 조회 1,339
RESTful 21-01-15 조회 1,438
RESTful 21-01-15 조회 1,337
해외사용자 21-01-15 조회 1,816
RESTful 21-01-14 조회 1,159
RESTful 21-01-14 조회 1,249
Node.js 21-01-14 조회 1,487
RESTful 21-01-14 조회 1,951
RESTful 21-01-13 조회 1,119
RESTful 21-01-12 조회 1,286
RESTful 21-01-12 조회 2,193
해외사용자 21-01-12 조회 1,874