我有json响应,我通过工具从这个json生成了java代码。但是这个json对象有@size,@ order等关键字......所以在我的java代码中生成了一些无效的标识符。当我用java代码删除这个@符号时,我能够捕获我的java对象中json值的响应,期望这些值。
我确信有一些json注释可用于执行此操作,意味着如果json键与java Object不匹配,那么我们可以映射此json注释。
我尝试了一些Json注释但是没有为我工作,我混淆了我应该使用getter方法注释哪些注释。
here my json code below :-
{
"HotelListResponse": {
"cachedSupplierResponse": {
"@cachedTime": "0",
"@candidatePreptime": "111",
"@matchedCurrency": "true",
"@matchedLocale": "true",
"@otherOverheadTime": "4",
"@supplierRequestNum": "211",
"@supplierResponseNum": "20",
"@supplierResponseTime": "405",
"@tpidUsed": "5001"
},
"cacheKey": "302c317:13443ffb599:-7712",
"cacheLocation": "10.186.168.61:7302",
"customerSessionId": "0ABAA83D-2C31-7913-4432-FFB599907714",
"HotelList": {
"@activePropertyCount": "237",
"@size": "1",
"HotelSummary": {
"@ubsScore": "1867",
"@order": "0",
"hotelId": 127092,
"name": "The Edgewater - A Noble House Hotel",
"address1": "Pier 67, 2411 Alaskan Way",
"city": "Seattle",
"stateProvinceCode": "WA",
"postalCode": 98121,
"countryCode": "US",
"airportCode": "SEA",
"supplierType": "E",
"propertyCategory": 1,
"hotelRating": 4,
"confidenceRating": 85,
"amenityMask": 6259019,
"tripAdvisorRating": 4,
"tripAdvisorReviewCount": 590,
"tripAdvisorRatingUrl": "http://www.tripadvisor.com/img/cdsi/img2/ratings/traveler/4.0-12345-4.gif",
"locationDescription": "Near Washington State Convention & Trade Center",
"shortDescription": "<p><b>Location. </b> <br />The Edgewater - A Noble House Hotel is a business-friendly hotel located in central Seattle, close to Odyssey - The Maritime Discovery Center, Washington State Convention &",
"highRate": 249,
"lowRate": 186.75,
"rateCurrencyCode": "USD",
"latitude": 47.61252,
"longitude": -122.35013,
"proximityDistance": 11.898841,
"proximityUnit": "MI",
"hotelInDestination": true,
"thumbNailUrl": "/hotels/1000000/20000/11200/11133/11133_73_t.jpg",
"deepLink": "http://travel.ian.com/index.jsp?pageName=hotAvail&cid=55505&hotelID=127092&mode=2&numberOfRooms=2&room-0-adult-total=1&room-0-child-total=1&room-0-child-0-age=3&room-1-adult-total=1&room-1-child-total=1&room-1-child-0-age=5&arrivalMonth=8&arrivalDay=4&departureMonth=8&departureDay=5&showInfo=true&locale=en_US¤cyCode=USD",
"RoomRateDetailsList": {
"RoomRateDetails": {
"roomTypeCode": 1160,
"rateCode": 1221260,
"maxRoomOccupancy": 2,
"quotedRoomOccupancy": 2,
"minGuestAge": 0,
"roomDescription": "City Lodge - Nonrefundable",
"promoId": 200803780,
"promoDescription": "7-Day Advance Purchase Special (Nonrefundable)",
"currentAllotment": 10,
"propertyAvailable": true,
"propertyRestricted": false,
"expediaPropertyId": 11133,
"rateKey": "f3525aff-9f4d-4d92-bc1c-144628fcaa30",
"nonRefundable": true,
"RateInfos": {
"@size": "1",
"RateInfo": {
"@rateChange": "false",
"@promo": "true",
"@priceBreakdown": "true",
"RoomGroup": {
"Room": [
{
"numberOfAdults": 1,
"numberOfChildren": 1,
"childAges": 3
},
{
"numberOfAdults": 1,
"numberOfChildren": 1,
"childAges": 5
}
]
},
"ChargeableRateInfo": {
"@commissionableUsdTotal": "373.5",
"@total": "441.74",
"@surchargeTotal": "68.24",
"@nightlyRateTotal": "373.5",
"@averageBaseRate": "249.0",
"@averageRate": "186.75",
"@maxNightlyRate": "186.75",
"@currencyCode": "USD",
"NightlyRatesPerRoom": {
"@size": "1",
"NightlyRate": {
"@promo": "true",
"@rate": "186.75",
"@baseRate": "249.0"
}
},
"Surcharges": {
"@size": "1",
"Surcharge": {
"@amount": "68.24",
"@type": "TaxAndServiceFee"
}
}
}
}
}
}
}
}
}
}
}
我通过这个工具生成了上面提到的json的java类:http://jsongen.byingtondesign.com/
所以这里如何在我们的java类中映射[@key(使用@开头的键值)]。最初java类有@identifier_name但是java编译器不支持变量名以@开头所以我必须删除它。然后我无法将json值映射到这个变量。
任何帮助都将不胜感激。
先谢谢