>
> HI
I have received the following json. Now i want to iterate it and send it to
the view. I need
tripId
ickupPointDetails object
ropoffPointDetails object
since they are at different levels i dont know how to segment them and send
it to view.
{"onwardTrips":[{"tripId":"1284876","fromCity":"Singapore","toCity":"Malacca","operatorCode":"SA","operatorName":"Starmart
Express","departTime":"2014-01-20
07:30:00.0","busType":"Executive","pickupPointDetails":[{"pickupPointId":"78","departureTime":"2014-01-20
07:30:00.0","pickupPointName":"Golden Mile Tower, Beach
Road"}],"dropoffPointDetails":[{"dropOffPointName":"Melaka
Sentral","dropOffPointId":"1284876"}],"fareDetails":{"adultFare":"65.0"}},{"tripId":"1284596","fromCity":"Singapore","toCity":"Malacca","operatorCode":"SA","operatorName":"Starmart
Express","departTime":"2014-01-20
08:30:00.0","busType":"Executive","pickupPointDetails":[{"pickupPointId":"78","departureTime":"2014-01-20
08:30:00.0","pickupPointName":"Golden Mile Tower, Beach
Road"}],"dropoffPointDetails":[{"dropOffPointName":"Melaka
Sentral","dropOffPointId":"1284596"}],"fareDetails":{"adultFare":"65.0"}},],"errorCode":0}
server,js
getTrips: function getTrips(req, res, next){
var url =
'http://ec2-54-251-114-65.ap-southeast-1.compute.amazonaws.com:8080/CTB-WS/rest/trips?from='+
req.tripinfo.fromCityId + '&to=' + req.tripinfo.toCityId + '&depart-date='
+ req.tripinfo.departDate+ '&pax=1';
console.log(url);
rest.get(url).on('complete', function(trips) {
if (trips instanceof Error) {
console.log('Error:', trips.message);
} else {
trips = trips || [];
req.trips = trips.map(function (p) {
console.log('p after mapping ' + p)
return p;
});
console.log('trips json parse ' + trips);
// segment trips
next();
}
});
},
sendTrips: function sendTrips(req, res, next){
res.render('trips', {trips : req.trips});
// send them to view
}
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.