Hi,
I have a json feed that I would like to extract information out from but for the last few days I’ve been struggling. I can target the item using the key but because the number of items in the object can vary which obviously then breaks my method.
E.g
var dayone1260 = data.SiteRep.DV.Location.Period[0].Rep[0];
console.log(dayone1260.Pp);
My Json feed looks like this:
<DV dataDate="2012-11-01T18:00:00Z" type="Forecast">
<Location i="310069" lat="50.7179" lon="-3.5327" name="EXETER" country="ENGLAND" continent="EUROPE">
<Period type="Day" value="2012-11-01Z">
<Rep D="W" F="5" G="25" H="71" Pp="48" S="9" T="8" V="EX" W="10" U="1">900</Rep>
<Rep D="W" F="5" G="47" H="78" Pp="59" S="4" T="7" V="EX" W="13" U="0">1080</Rep>
<Rep D="SW" F="3" G="25" H="82" Pp="58" S="9" T="6" V="EX" W="13" U="0">1260</Rep>
</Period>
<Period type="Day" value="2012-11-02Z">
<Rep D="WSW" F="3" G="34" H="85" Pp="38" S="11" T="6" V="GO" W="19" U="0">0</Rep>
<Rep D="WSW" F="3" G="20" H="80" Pp="1" S="9" T="6" V="EX" W="2" U="0">180</Rep>
<Rep D="SW" F="3" G="18" H="86" Pp="9" S="7" T="5" V="VG" W="2" U="0">360</Rep>
<Rep D="SSW" F="5" G="13" H="82" Pp="4" S="4" T="6" V="VG" W="3" U="1">540</Rep>
<Rep D="WNW" F="6" G="22" H="77" Pp="28" S="7" T="8" V="VG" W="3" U="1">720</Rep>
<Rep D="WSW" F="8" G="22" H="68" Pp="8" S="9" T="10" V="EX" W="3" U="1">900</Rep>
<Rep D="WSW" F="5" G="18" H="78" Pp="1" S="7" T="7" V="EX" W="2" U="0">1080</Rep>
<Rep D="SW" F="5" G="13" H="81" Pp="7" S="7" T="6" V="VG" W="2" U="0">1260</Rep>
</Period>
<Period type="Day" value="2012-11-03Z">
<Rep D="WSW" F="4" G="13" H="82" Pp="2" S="7" T="6" V="EX" W="2" U="0">0</Rep>
<Rep D="SW" F="3" G="16" H="83" Pp="7" S="7" T="6" V="EX" W="2" U="0">180</Rep>
<Rep D="W" F="3" G="11" H="84" Pp="2" S="7" T="5" V="VG" W="2" U="0">360</Rep>
<Rep D="W" F="2" G="18" H="85" Pp="38" S="9" T="5" V="GO" W="10" U="1">540</Rep>
<Rep D="W" F="4" G="20" H="76" Pp="43" S="9" T="7" V="EX" W="10" U="1">720</Rep>
<Rep D="WSW" F="2" G="18" H="82" Pp="44" S="9" T="5" V="VG" W="10" U="1">900</Rep>
<Rep D="N" F="2" G="11" H="86" Pp="15" S="4" T="4" V="VG" W="7" U="0">1080</Rep>
<Rep D="SSW" F="1" G="11" H="86" Pp="6" S="7" T="4" V="EX" W="0" U="0">1260</Rep>
</Period>
....More reports
</Location>
</DV>
</SiteRep>
Is there a better way to obtain the .Pp value in a variable so I can then use / display it on the page. Using the ‘value’ of <Rep>?
My javascript knowledge is limited to jquery front end stuff to date so sorry if I’ve not explained this very well.