0
我正在使用樹屋庫學習iOS開發。構建一個從json API獲取信息的應用程序。使用我的Rails應用程序API for iPhone應用程序
在樹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「包裝」到父項下? (我的模型被稱爲「發佈」)
謝謝你,我會考慮這樣做。 – ChrisBedoya
,或者在你的rails控制器中執行如下操作:'render json:releases:@ releases' – macool