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 trialMUZ140651 Patience Muchirahondo
4,123 PointsThe data in the file data.json has been loaded into a JSONObject named jsonData. Using data.json
where m i missing it
// A JSONObject variable named 'jsonData'
// was loaded from the data.json file.
private CurrentDetails getCurrentDetails(String jsonData) {
JSONObject = new JSONObject(jsonData);
String name = jsonData.getString("name");
String publisher = jsonData.getString("publisher");
String language = jsonData.getString("language");
{
"name":"Treehouse Book Series",
"publisher":"Wiley",
"language":"English",
"books":[
{
"title":"HTML5 Foundations",
"author":"Matt West",
"pages":384
},
{
"title":"CSS3 Foundations",
"author":"Ian Lunn",
"pages":352
}
]
}
2 Answers
Steve Hunter
57,712 PointsHi there,
The variable jsonData
is already a JSONObject
. So, you need to simplify your code a little:
String name = jsonData.getString("name");
String publisher = jsonData.getString("publisher");
String language = jsonData.getString("language");
Hope that helps!
Steve.
MUZ140651 Patience Muchirahondo
4,123 PointsThanx lots Steve, it helped
MUZ140668 Gilbert Sibanda
4,918 PointsMUZ140668 Gilbert Sibanda
4,918 Pointscan you post the full question of your code challenge