Restful에서 리턴되는 JSON 값

· 5년 전 · 1007

제일 앞에 나오는 값이 단수라면 뒤에는 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로 매핑해서 각각을 사용하면 되는 것 같습니다.

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

RESTful

+
제목 글쓴이 날짜 조회
4년 전 조회 1,059
4년 전 조회 874
4년 전 조회 1,429
4년 전 조회 706
4년 전 조회 1,123
4년 전 조회 1,691
4년 전 조회 1,447
4년 전 조회 1,404
4년 전 조회 1,027
4년 전 조회 1,226
5년 전 조회 1,161
5년 전 조회 998
5년 전 조회 1,027
5년 전 조회 975
5년 전 조회 1,008
5년 전 조회 721
5년 전 조회 1,159
5년 전 조회 1,207
5년 전 조회 1,724
5년 전 조회 1,838
5년 전 조회 873
5년 전 조회 1,089
5년 전 조회 981
5년 전 조회 849
5년 전 조회 954
5년 전 조회 1,560
5년 전 조회 831
5년 전 조회 983
5년 전 조회 1,900
5년 전 조회 2,907
🐛 버그신고