2011-11-16 63 views
0

我想通過SpaceType,TimeInterval和Price對對象進行排序。它是一個嵌套的對象,如下所示。有人建議我如何使用C#4.0使用c嵌套對象的排序值#

ParkingFacility以高效的方式,排序樣品 - >成本 - > TimeInterval所

"VendorID": 1200, 
"FacilityID": 931, 
"ParkingType": "Garage", 
"Price": null, 
"BARTValidationRequired": null, 
"LotName": "Civic Center Garage", 
"City": "San Francisco", 
"Street": "355 McAllister Street", 
"Neighborhood": "Hayes Valley/Civic Center", 
"Latitude": "37.780200", 
"Longitude": "-122.417800", 
"Distance": "", 
"Availability": "Space Available: <b>62%</b> (515/843) <br/>Current Price: <b>N/A</b><br />6:00 AM-12:00 AM", 
"Details": null, 
"Hours": "Sunday : 9:00 AM-10:00 PM <br />Monday : 6:00 AM-12:00 AM <br />Tuesday : 6:00 AM-12:00 AM <br />Wednesday : 6:00 AM-12:00 AM <br />Thursday : 6:00 AM-12:00 AM <br />Friday : 6:00 AM-12:00 AM <br />Saturday : 8:00 AM-12:00 AM <br />", 
"Entrance": null, 
"Contact": "", 
"TodayTimings": "6:00 AM-12:00 AM", 
"TotalParkingSpace": 843, 
"AvailableParkingSpace": 515, 
"OccupiedParkingSpace": 328, 
"PercentFull": 38, 
"Rendering": 3, 
"ZoneID": 0, 
"OwnershipAgencyType": null, 
"Cost": [ 
[ 
    { 
     "DayType": "Thursday", 
     "SpaceType": "Motorcycle", 
     "Description": "Motorcycle: Flatrate", 
     "TimeInterval": 0, 
     "Cost": "$5.00", 
     "FaciltyID": 0 
    }, 
    { 
     "DayType": "Thursday", 
     "SpaceType": "Auto", 
     "Description": null, 
     "TimeInterval": 0, 
     "Cost": "$5.00", 
     "FaciltyID": 0 
    } 
], 
[ 
    { 
     "DayType": "MondayToFridayExceptHolidays", 
     "SpaceType": "Auto", 
     "Description": "Early Bird: Flat rate. Mon-Fri (excl. Tue): In by 9AM/Out by 7PM;No Tues Early Bird", 
     "TimeInterval": 0, 
     "Cost": "$15.00", 
     "FaciltyID": 0 
    } 
], 
[ 
    { 
     "DayType": "Thursday", 
     "SpaceType": "Auto", 
     "Description": "Per hour", 
     "TimeInterval": 60, 
     "Cost": "$3.00", 
     "FaciltyID": 0 
    }, 
    { 
     "DayType": "Thursday", 
     "SpaceType": "Auto", 
     "Description": "12-Hour Max", 
     "TimeInterval": 720, 
     "Cost": "$24.00", 
     "FaciltyID": 0 
    }, 
    { 
     "DayType": "Thursday", 
     "SpaceType": "Auto", 
     "Description": "24-Hour Max/Lost Tkt", 
     "TimeInterval": 0, 
     "Cost": "$30.00", 
     "FaciltyID": 0 
    }, 
    { 
     "DayType": "Thursday", 
     "SpaceType": "Auto", 
     "Description": null, 
     "TimeInterval": 0, 
     "Cost": "$30.00", 
     "FaciltyID": 0 
    } 
]] 
} 

回答

2

因此,假如你擁有了它在C#中,你可以使用LINQ的結構由多個項目訂購。

例如

listOfPeople.OrderBy(person => person.LastName) 
     .ThenBy(person => person.FirstName) 
     .ThenBy(person => person.DOB) 

當然,這是一個簡單的例子,但是這取決於你如何希望他們整理 - 如果自己的集裝箱或全部內爲一個 - 你可以運行這個迭代器。它非常高效 - 比我們更好的程序員。

可能更困難的是如何對spaceType進行排序 - 就像這樣做會按字母順序排列,這可能不是您想要的。

+0

我遇到的問題不是排序順序,而是如何根據稱爲時間間隔的嵌套對象對停車設施對象的根結構進行排序。 ParkingFacility包含一個成本對象。成本對象包含一個FaciltyPrice對象,它是價格對象的列表。從列表對象我可以得到旅行時間,但按旅行時間排序停車設施是我沒有線索如何做到這一點。請參考我發佈的對象。它是我當前對象的確切json表示,我需要對它進行排序 – Pawan

+0

是否有可能在代碼中添加一個簡化模型,只需要您想要排序的元素 - 以及您想要的方式的描述看。我仍然不是100%想要分類哪個對象,以及您想要對它們進行排序的條件。多願意幫助壽! –

+0

rangitatanz:謝謝你的幫助。我想到了。我最初使用的邏輯是不正確的。 – Pawan

相關問題