我有以下JSON數據:按數據分組JSON?
{
"events":
{
"event":
[
{
"city":"Birmingham",
"state":"AL",
"country":"US",
"lat":"33.5206608",
"lng":"-86.80249",
"status":"Delivered",
"occured_at":"2012-04-06
14:17:00 UTC"
},
{
"city":"Birmingham",
"state":"AL",
"country":"US",
"lat":"33.5206608",
"lng":"-86.80249",
"status":"Out
For Delivery",
"occured_at":"2012-04-06 04:44:00 UTC"
},
{
"city":"Birmingham",
"state":"AL",
"country":"US",
"lat":"33.5206608",
"lng":"-86.80249",
"status":"Arrival
Scan",
"occured_at":"2012-04-05 19:07:00 UTC"
},
{
"city":"Doraville",
"state":"GA",
"country":"US",
"lat":"33.8981579",
"lng":"-84.2832564",
"status":"Departure
Scan",
"occured_at":"2012-04-05 17:08:00 UTC"
},
{
"city":"Doraville",
"state":"GA",
"country":"US",
"lat":"33.8981579",
"lng":"-84.2832564",
"status":"Arrival
Scan",
"occured_at":"2012-04-05 11:15:00 UTC"
},
{
"city":"Spartanburg",
"state":"SC",
"country":"US",
"lat":"34.9495672",
"lng":"-81.9320482",
"status":"Departure
Scan",
"occured_at":"2012-04-05 08:42:00 UTC"
},
{
"city":"Spartanburg",
"state":"SC",
"country":"US",
"lat":"34.9495672",
"lng":"-81.9320482",
"status":"Arrival
Scan",
"occured_at":"2012-04-05 08:21:00 UTC"
},
{
"city":"Greensboro",
"state":"NC",
"country":"US",
"lat":"36.0726354",
"lng":"-79.7919754",
"status":"Departure
Scan",
"occured_at":"2012-04-05 04:45:00 UTC"
},
{
"city":"Greensboro",
"state":"NC",
"country":"US",
"lat":"36.0726354",
"lng":"-79.7919754",
"status":"Origin
Scan",
"occured_at":"2012-04-05 00:11:00 UTC"
},
{
"city":null,
"state":null,
"country":"US",
"status":"Billing
Information Received",
"occured_at":"2012-04-04 18:20:27 UTC"
}
]
}
}
我需要做的是團體經市,州和國家的組合數據,但仍從每個項目返回數據。
因此,例如,「伯明翰,AL,美國」組,但仍然能夠遍歷每個事件的status
(即交付,送貨,到達掃描)。
事實上,這是JSON是真的無關緊要,對吧?您可以使用'JSON.parse'將其轉換爲Ruby哈希,然後使用該哈希(如果需要,最終將其返回給JSON)。 – Phrogz 2012-04-12 03:30:14