Solved

processing JSON advanced

Posted on 2014-10-15
4
135 Views
Last Modified: 2014-10-16
I have the following JSON I was wondering how would you process it using JavaScript

I want to console.log teamname. SportsTypes

[
  {
    "teamname": "Bulldogs",
    "nickname": "",
    "SportTypes": {
      "-JZLOh7KtM78I5wAL6Ua": true
    },
    "locations": {
      "-JZLCFtpcuvsYxb5N1Cc": true
    }
  }
]

Open in new window

0
Comment
Question by:stargateatlantis
  • 3
4 Comments
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 40383483
Assuming the code you've posted is in myobject:

Console.log(myobject[0].teamname);
Console.log(myobject[0].SportTypes);
0
 

Author Comment

by:stargateatlantis
ID: 40383569
So would I do this

Console.log(myobject[0].SportTypes['-JZLOh7KtM78I5wAL6Ua']);

Open in new window

0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 40383583
Yes, that is what you'd need to do to get that value.

You could also use the for/in loop to get the value too
0
 
LVL 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 500 total points
ID: 40383588
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now