0

我正在使用 Treehouse Library 学习 iOS 开发。构建一个从 json API 获取信息的应用程序。

在 Treehouse API 页面中,所有帖子都在名为“帖子”的父级下(http://blog.teamtreehouse.com/api/get_recent_summary/

posts: [
{
  id: 22198,
  url: "http://blog.teamtreehouse.com/using-github-pages-to-host-your-website",
  title: "Using GitHub Pages To Host Your Website",
  date: "2013-08-16 09:30:20",
  author: "Matt West",
  thumbnail: "http://blog.teamtreehouse.com/wp-content/uploads/2013/08/github-pages-feature-150x150.jpg"
},
{
  id: 22196,
  url: "http://blog.teamtreehouse.com/running-tests-in-ruby-on-rails-treehouse-quick-tip",
  title: "Running Tests in Ruby on Rails – Treehouse Quick Tip",
  date: "2013-08-15 14:30:48",
  author: "Jason Seifer",
  thumbnail: null
},

我的 Rails 应用程序的 API 没有父级(http://www.soleresource.com/releases.json

[
{
  shoe_name: "Air Jordan 4 "Green Glow"",
  release_date: "2013-08-17T00:00:00.000Z",
  shoe_colorway: "Dark-Grey/Green-Glow",
  shoe_price: "160",
  url: "http://www.soleresource.com/releases/8.json"
},
{
  shoe_name: "Nike Barkley Posite",
  release_date: "2013-08-17T00:00:00.000Z",
  shoe_colorway: "Gamma-Green/Black",
  shoe_price: "235",
  url: "http://www.soleresource.com/releases/17.json"
},

为了让应用程序正常工作,我必须打电话给家长(帖子),如下所示:

 self.upcomingReleases = [dataDictionary objectForKey:@"posts"];

我怎样才能将我的 API “包装”在 Parent 下?(我的模型叫做“Releases”)

4

1 回答 1

0

恕我直言,如果您将 Rails 应用程序用作 REST API,则绝对应该使用ActiveModel::Serializer。它可以让您为 JSON 响应指定所有内容,例如元数据

这是一个 RailsCast:http ://railscasts.com/episodes/409-active-model-serializers

于 2013-08-18T21:46:09.797 回答