On Jan 19, 2014, at 10:24 PM, Jyoti Chhetri <[email protected]> wrote:
> I have following json. At first I need to get the tripId, fromCity, toCity.
>
> Then based on tripId I need to get pickupPointDetails and
> dropoffPointDetails. Please help me do this, I m very new to json and node js
> and I need to get this done and its already taken so long and still i havent
> found the solution
>
Jyoti,
a suggestion: this (and some of your other) question are generic JavaScript
questions and not specific to NodeJS. I suspect you will get better turnaround
asking on a general JavaScript beginner mailing list or on StackOverflow.
The JSON you included is invalid (see the part following the property “busType”
which has an unterminated quoted value. Assuming the quote ends after
“Executive” and there is no closing curly brace that follows:
onwardtrips.pickupPointDetails will let you reference the array with the pickup
points, and you can iterate through this array using forEach to process each
element:
onward trips.pickupPointDetails.forEach
(
function(pickupPoint)
{
console.log(“TripID is “ + element.tripId);
….
}
);
Similarly for dropoffPointDetails.
Regards,
—ravi
> var onwardtrips = {
> "tripId":"1284792",
> "fromCity":"Singapore",
> "toCity":"Malacca",
> "operatorCode":"SA",
> "operatorName":"Starmart Express",
> "departTime":"2014-01-20 14:00:00.0",
> "busType":"Executive
> },
> pickupPointDetails":[
> {
> "pickupPointId":"78",
> "departureTime":"2014-01-20 14:00:00.0",
> "pickupPointName":"Golden Mile Tower, Beach Road"
> }
> ],
> "dropoffPointDetails":[
> {
> "dropOffPointName":"Melaka Sentral",
> "dropOffPointId":"1284792"}
> ]
> }
>
--
--
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.