簡體   English   中英

使用對象映射器解析復雜的JSON

[英]Parse Complex JSON with Object Mapper

I am trying to parse complex JSON response using REST template.

`[
{
"message": "address_matched",
"location": "433 merwyn road merion station pa",
"resultcountformatted": "488",
"resultcount": 488,
"pagerdata": {
"Current": 1,
"Pages": 55,
"ResultStart": 0,
"ResultEnd": 0,
"TotalResults": 488,
"PageList": [
{
"PageNumber": "1",
"PageURL": "/realestatehomesforsale/19066-p001.html?query=geodist-aorder"
},
{
"PageNumber": "2",
"PageURL": "/realestatehomesforsale/19066-p002.html?query=geodist-aorder"
},
{
"PageNumber": "3",
"PageURL": "/realestatehomesforsale/19066-p003.html?query=geodist-aorder"
},
{
"PageNumber": "4",
"PageURL": "/realestatehomesforsale/19066-p004.html?query=geodist-aorder"
},
{
"PageNumber": "5",
"PageURL": "/realestatehomesforsale/19066-p005.html?query=geodist-aorder"
},
{
"PageNumber": "6",
"PageURL": "/realestatehomesforsale/19066-p006.html?query=geodist-aorder"
},
{
"PageNumber": "7",
"PageURL": "/realestatehomesforsale/19066-p007.html?query=geodist-aorder"
},
{
"PageNumber": "8",
"PageURL": "/realestatehomesforsale/19066-p008.html?query=geodist-aorder"
},
{
"PageNumber": "9",
"PageURL": "/realestatehomesforsale/19066-p009.html?query=geodist-aorder"
},
{
"PageNumber": "10",
"PageURL": "/realestatehomesforsale/19066-p010.html?query=geodist-aorder"
},
{
"PageNumber": "..."
},
{
"PageNumber": "20",
"PageURL": "/realestatehomesforsale/19066-p020.html?query=geodist-aorder"
},
{
"PageNumber": "30",
"PageURL": "/realestatehomesforsale/19066-p030.html?query=geodist-aorder"
},
{
"PageNumber": "40",
"PageURL": "/realestatehomesforsale/19066-p040.html?query=geodist-aorder"
},
{
"PageNumber": "50",
"PageURL": "/realestatehomesforsale/19066-p050.html?query=geodist-aorder"
},
{
"PageNumber": "55",
"PageURL": "/realestatehomesforsale/19066-p055.html?query=geodist-aorder"
}
],
"PagesPerSet": 10,
"ItemsPerPage": 9
},
"lat": 40.004202,
"office": {
"OfficeListingsCount": 0,
"OfficeListings": [],
"PageNumber": 1,
"PageSize": 6,
"OfficeName": "quantro.remax.com",
"VirtualOfficeAllowed": true,
"ShowListingInformationSponsoredby": true,
"OfficeDetailURL": "/realestateofficerealtor/quantroremaxcom-id68000000.html",
"Address1": "",
"City": "",
"State": "",
"Zip": "",
"Phone": "",
"LicenseNumber": "",
"OfficeID": 68000000,
"PhotoRef": "https://matrix.remax.net/profileimages/balloonImage.jpg",
"HasOfficeOwners": false,
"IsGeoCoded": false,
"OfficeGeoCheckLevelCode": 0,
"SiteURL": "quantro.remax.com",
"Protocol": "https",
"SiteID": "68000000",
"Lat": 0,
"Lng": 0,
"AgentCount": 0,
"HideSocialWall": false,
"ShowListings": false,
"OfficeOwners": [],
"OfficeManagers": [],
"SearchSiteURL": "www.remax.com",
"ShowDetailsURL": false,
"ShowLogo": true,
"ShowContact": true,
"AccountID": 0,
"TagLine": "",
"MowSiteID": 0,
"IsMow": false
},
"long": -75.254086
},
[
{
"IsHomeValue": true,
"IsForeclosure": false,
"SoldDateFormatted": "6/27/2002",
"PriceFormatted": "380,000",
"AVMPriceFormatted": "597,668",
"ListingDetailURL": "/realestatehomesforsale/433-merwyn-rd-merion-station-pa-19066-gid400024907235.html",
"GlobalListingDetailURL": "/realestatehomesforsale/433-merwyn-rd-merion-station-pa-19066-gid400024907235.html",
"sz_id": 400024907235,
"ListingID": 0,
"ValueListingTypeID": 0,
"Address": "433 MERWYN RD",
"City": "MERION STATION",
"street_name": "MERWYN RD",
"State": "PA",
"Zip": "19066",
"SqFt": "2897",
"SqFtFormatted": "2,897",
"avm": "597668",
"History": [],
"ValueSearchType": 1,
"ValueSearchTypeText": "NOT FOR SALE",
"SiteID": 0,
"YearBuilt": 1958,
"BedRooms": 5,
"BathRooms": 4,
"Latitude": 40.004202,
"Longitude": -75.254086
},
{
"IsHomeValue": true,
"IsForeclosure": false,
"SoldDateFormatted": "7/14/1999",
"PriceFormatted": "245,000",
"AVMPriceFormatted": "516,630",
"ListingDetailURL": "/realestatehomesforsale/429-merwyn-rd-merion-station-pa-19066-gid400024907236.html",
"GlobalListingDetailURL": "/realestatehomesforsale/429-merwyn-rd-merion-station-pa-19066-gid400024907236.html",
"sz_id": 400024907236,
"ListingID": 0,
"ValueListingTypeID": 0,
"Address": "429 MERWYN RD",
"City": "MERION STATION",
"street_name": "MERWYN RD",
"State": "PA",
"Zip": "19066",
"SqFt": "2313",
"SqFtFormatted": "2,313",
"avm": "516630",
"History": [],
"ValueSearchType": 1,
"ValueSearchTypeText": "NOT FOR SALE",
"SiteID": 0,
"YearBuilt": 1958,
"BedRooms": 4,
"BathRooms": 3,
"Latitude": 40.004024,
"Longitude": -75.253908
},
{
"IsHomeValue": true,
"IsForeclosure": false,
"PriceFormatted": "300,000",
"AVMPriceFormatted": "581,476",
"ListingDetailURL": "/realestatehomesforsale/516-narberth-ave-merion-station-pa-19066-gid400024908056.html",
"GlobalListingDetailURL": "/realestatehomesforsale/516-narberth-ave-merion-station-pa-19066-gid400024908056.html",
"sz_id": 400024908056,
"ListingID": 0,
"ValueListingTypeID": 0,
"Address": "516 NARBERTH AVE",
"City": "MERION STATION",
"street_name": "NARBERTH AVE",
"State": "PA",
"Zip": "19066",
"SqFt": "2996",
"SqFtFormatted": "2,996",
"avm": "581476",
"History": [],
"ValueSearchType": 1,
"ValueSearchTypeText": "NOT FOR SALE",
"SiteID": 0,
"YearBuilt": 1920,
"BedRooms": 5,
"BathRooms": 4,
"Latitude": 40.000613,
"Longitude": -75.258385
}
]
]`

對於上面的嘗試找出POJO的響應,我嘗試了幾個POJO層次結構來解析這些Json無法找出來的東西,有人可以建議我POJO來解析它嗎?

實際上,JSON響應具有包含對象的JSON數組列表,還有一個沒有對象的數組,並且很難使用對象映射器將任何映射庫映射到該響應的數組,但是我們能否獲得幫助來構建此響應的對象模型。

您有三種選擇:

  1. 請與API提供程序聯系,以了解API的Swagger / OpenAPI定義。 如果有的話,您可以使用Swagger Codegen生成代碼。

  2. 查找API文檔,並根據手工定義的模型編寫Java類。

  3. 如果您沒有時間處理第2點,則可以使用quicktype ,它直接從JSON示例生成代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM