Created
September 6, 2014 09:26
-
-
Save zulhfreelancer/2c98cddc48de5803a014 to your computer and use it in GitHub Desktop.
Get Data From JSON Array Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
/* | |
This is the example of how to get data from JSON Array Object | |
If you want to get earliest data, you need to know the data length first. Then use 'jsonobject.data.length-1' to get it. | |
Uncomment my example to see how it's work | |
DEMO: http://jsfiddle.net/bpphzwgx/ | |
*/ | |
var jsonobject = { | |
"meta":{ | |
"author":"@h4ck4life", | |
"about":"Pos Laju Tracking API", | |
"email":"alifaziz@gmail.com", | |
"version":"0.0.4" | |
}, | |
"data":[ | |
{ | |
"date":"03-Sep-2014", | |
"time":"14:52:58", | |
"process":"Delivered to ZULHILMI", | |
"office":"PPL KUANTAN" | |
}, | |
{ | |
"date":"03-Sep-2014", | |
"time":"08:01:28", | |
"process":"Delivery process", | |
"office":"PPL KUANTAN" | |
}, | |
{ | |
"date":"03-Sep-2014", | |
"time":"07:23:02", | |
"process":"Arrive at delivery office", | |
"office":"PPL KUANTAN" | |
}, | |
{ | |
"date":"02-Sep-2014", | |
"time":"22:06:51", | |
"process":"Consignment dispatch out from Transit Office", | |
"office":"PPL KUALA LUMPUR" | |
}, | |
{ | |
"date":"02-Sep-2014", | |
"time":"21:52:24", | |
"process":"Consignment arrived at Transit office", | |
"office":"PPL KUALA LUMPUR" | |
}, | |
{ | |
"date":"02-Sep-2014", | |
"time":"20:01:54", | |
"process":"Consignment dispatch out from Transit Office", | |
"office":"PPL KAJANG" | |
}, | |
{ | |
"date":"27-Aug-2014", | |
"time":"18:04:30", | |
"process":"Self collection at counter", | |
"office":"PPL KAJANG" | |
}, | |
{ | |
"date":"20-Aug-2014", | |
"time":"20:32:56", | |
"process":"Self collection at counter", | |
"office":"PPL KAJANG" | |
}, | |
{ | |
"date":"20-Aug-2014", | |
"time":"19:03:53", | |
"process":"Self collection at counter", | |
"office":"PPL KAJANG" | |
}, | |
{ | |
"date":"20-Aug-2014", | |
"time":"14:52:19", | |
"process":"Unsuccessful delivery to Addressee not available", | |
"office":"PPL KAJANG" | |
}, | |
{ | |
"date":"20-Aug-2014", | |
"time":"08:51:44", | |
"process":"Delivery process", | |
"office":"PPL KAJANG" | |
}, | |
{ | |
"date":"20-Aug-2014", | |
"time":"07:19:07", | |
"process":"Arrive at delivery office", | |
"office":"PPL KAJANG" | |
}, | |
{ | |
"date":"19-Aug-2014", | |
"time":"15:09:34", | |
"process":"Consignment received and processed from posting at Post Offices", | |
"office":"PPL KUANTAN" | |
} | |
] | |
}; | |
// latest data | |
var latest_process = jsonobject.data[0].process; | |
var latest_date = jsonobject.data[0].date; | |
var latest_time = jsonobject.data[0].time; | |
var latest_office = jsonobject.data[0].office; | |
alert(latest_process); | |
alert(latest_date); | |
alert(latest_time); | |
alert(latest_office); | |
/* earliest data | |
var first_process = jsonobject.data[jsonobject.data.length-1].process; | |
var first_date = jsonobject.data[jsonobject.data.length-1].date; | |
var first_time = jsonobject.data[jsonobject.data.length-1].time; | |
var first_office = jsonobject.data[jsonobject.data.length-1].office; | |
alert(first_process); | |
alert(first_date); | |
alert(first_time); | |
alert(first_office); | |
*/ | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment