Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Thomas Skjelstad
11,541 PointsProduct catalog
I am trying to figure out the best way to make a product catalog. I want to be able to drill down to a detail view using tableViews.
I have 5 product lines. and each product line has 20 products. In a detail view i want to display an Image, name, description and a youtube video.
what i am wondering about is. What is the best way to store this information. JSON file, PLIST file, XML file, or write it in programatically?
Any help would be appreciated.
5 Answers
Alex Hedley
16,381 PointsWill it be a one off list? Will you be updating it often, so keep a list on a web server?
If it's local you could have a plist or JSON file. You could use SQLite, this might be overkill for (5x20) items.
The Blog Reader would easily be adaptable to this.
Thomas Skjelstad
11,541 PointsThe file with the content would be on a web server for easy updates if needed. I would have to write the JSON file manually.
could it be written like this
{
"Products": {
"thunder": {
"Mammoth": {
"name": "Mammoth",
"info": "Firework battery"
},
"NoLimit": {
"name": "No Limit",
"info": "Firework battery"
}
},
"Hotstuff": {
"goldrush": {
"name": "Gold Rush",
"info": "Firework battery"
},
"thebeast": {
"name": "The Beast",
"info": "Firework battery"
}
}
} }
Alex Hedley
16,381 PointsYou can write it in the way that best suits your needs. Take a look at the Treehouse Blog API:
{"posts":[{"id":22230,"url":"http:\/\/blog.teamtreehouse.com\/build-a-self-destructing-messaging-app-for-the-iphone","title":"Build a Self-Destructing Messaging App for the iPhone","date":"2013-08-28 09:47:31","author":"Treehouse","thumbnail":null}]}
Then you could amend that to your fields:
{ "products": [ { "id":1, "image":"http:\/\/www.images.com\/image1.png", "name":"...", "description":"blah blah", "video_url":"http:\/\/www.youtube.com\/v\/123" }, { ADD MORE PRODUCTS } ] }
Thomas Skjelstad
11,541 Pointswhy does JSON have untraditional http:\/\/blog.teamtreehouse.com\/build-a-self-destructing-messaging-app-for-the-iphone" / in the address?
Alex Hedley
16,381 Pointsyou need to escape certain characters like /.
\" \ \/ \b \f \n \r \t \u four-hex-digits
\b Backspace (ascii code 08) \f Form feed (ascii code 0C) \n New line \r Carriage return \t Tab \v Vertical tab \' Apostrophe or single quote \" Double quote \ Backslash character
Thomas Skjelstad
11,541 PointsGood to know, thank you.