Reputation: 15925
From the following json snippet:
cbfunc22({
query: {
count: 2,
created: "2012-06-18T11:18:15Z",
lang: "en-US",
results: {
tbody: [{
tr: [{
class: "day",
td: [{
class: "dayname",
p: "Monday"
},
{
class: "weather",
p: "Sunny Intervals"
},
I can extract Monday
using jQuery as follows:
data.query.results.tbody[0].tr[0].td[0].p
How do I extract Sunny Intervals
?
Upvotes: 0
Views: 132
Reputation: 3028
td[0]
is for Monday so td[1]
is for Sunny Intervals and so on
so Sunny Intervals can be extracted by,
data.query.results.tbody[0].tr[0].td[1].p
Upvotes: 0
Reputation: 150030
td
is an array, so index 0 gives the first element, index 1 gives the second:
data.query.results.tbody[0].tr[0].td[1].p
and so forth...
Upvotes: 0
Reputation: 9847
Just use:
data.query.results.tbody[0].tr[0].td[1].p
If you indent your code correctly the solution is more apparent:
cbfunc22(
{
query: {
count: 2,
created: "2012-06-18T11:18:15Z",
lang: "en-US",
results: {
tbody: [
{
tr: [
{
class: "day",
td: [
{
class: "dayname",
p: "Monday"
},
{
class: "weather",
p: "Sunny Intervals"
},
Upvotes: 0