chris
chris

Reputation: 36947

Stuck working with JSON object

I have a JSON object that looks similar to

{
   "mydata":[
            "one",
            "two",
            "three"
            ],
   "outside":[
               {
                 "vals":["four", "five", "six"],
                 "soso":{"seven", "eight", "nine"]               
               },
               {
                 "vals":["four", "five", "six"],
                 "soso":{"seven", "eight", "nine"]               
               },
               {
                 "vals":["four", "five", "six"],
                 "soso":{"seven", "eight", "nine"]               
               },
              ]
   "inside":[]

and I am trying to with jquery run $.each on "outside" so I can get each vals set of values from "outside" and im not getting anything but am failing misserably ive given up hoping someone can assist

Upvotes: 0

Views: 91

Answers (2)

thecodeparadox
thecodeparadox

Reputation: 87073

Within outside object soso should look like this

"soso":["seven", "eight", "nine"] and then

$.each(json.outside, function() {
    this.vals.each(function(index, val) {
       console.log(val); // output: "four", "five", "six"
    });

   this.soso.each(function(index, val) {
       console.log(val); // output: "seven", "eight", "nine
    });
});

Upvotes: 2

robrich
robrich

Reputation: 13205

Using jQuery:

$.each(jsonObj.outside, function () {
    var i = this; // The current item
});

Upvotes: 1

Related Questions