Reputation: 333
I have a nested JSON object that I am having trouble parsing. The stuucture is as follows
{
"status": {
"version": "1.0.0",
"code": 0,
"msg": "SuccessWithResult",
"total": 1,
"page": 1,
"pagesize": 10
},
"property": [
{
"identifier": {
"obPropId": 2511639610001,
"fips": "10001",
"apn": "11701014062800000",
"apnOrig": "1-17-010.14-06-28.00-000"
},
"lot": {
"depth": 110,
"frontage": 22,
"lotnum": "28",
"lotsize1": 600,
"lotsize2": 2614
},
"area": {
"countrysecsubd": "Kent County",
"countyuse1": "P",
"muncode": "17",
"munname": "DUCK CREEK",
"subdname": "WOODLAND MANOR PH I",
"taxcodearea": "17"
},
"address": {
"country": "US",
"countrySubd": "DE",
"line1": "468 SEQUOIA DR",
"line2": "SMYRNA, DE 19977",
"locality": "Smyrna",
"matchCode": "ExaStr",
"oneLine": "468 SEQUOIA DR, SMYRNA, DE 19977",
"postal1": "19977",
"postal2": "2542",
"postal3": "C003"
},
"location": {
"accuracy": "Street",
"elevation": 0,
"latitude": "39.302769",
"longitude": "-75.594399",
"distance": 0,
"geoid": "MT30001363,PL1067310,RS0000330264,SD67611,SS155012,SS198222,SS201397,SS201759"
},
"summary": {
"absenteeInd": "OWNER OCCUPIED",
"propclass": "Apartment",
"propsubtype": "SINGLE FAMILY",
"proptype": "APARTMENT",
"yearbuilt": 2006,
"propLandUse": "APARTMENT"
},
"utilities": {
"coolingtype": "TYPE UNKNOWN",
"heatingtype": "WARM AIR",
"wallType": "ALUMINUM"
},
"building": {
"size": {
"bldgsize": 2145,
"grosssize": 0,
"grosssizeadjusted": 0,
"groundfloorsize": 0,
"livingsize": 1738,
"sizeInd": "LIVING SQFT ",
"universalsize": 1738
},
"rooms": {
"bathfixtures": 10,
"baths1qtr": 0,
"baths3qtr": 0,
"bathscalc": 3,
"bathsfull": 2,
"bathshalf": 1,
"bathstotal": 3,
"beds": 3,
"roomsTotal": 6
},
"interior": {
"bsmtsize": 715,
"bsmttype": "UNFINISHED",
"fplccount": 0
},
"construction": {
"condition": "GOOD",
"wallType": "ALUMINUM"
},
"parking": {
"prkgSize": 0,
"prkgSpaces": "0"
},
"summary": {
"archStyle": "TYPE UNKNOWN",
"bldgsNum": 1,
"bldgType": "SINGLE FAMILY",
"levels": 2,
"storyDesc": "SINGLE FAMILY",
"unitsCount": "0",
"yearbuilteffective": 0
}
},
"vintage": {
"lastModified": "2015-4-3",
"pubDate": "2015-5-9"
}
}
]
}
To access the data I am using
$.ajax({
type: "get",
dataType: 'json',
url: "https://search.onboard-apis.com/propertyapi/v1.0.0/property/detail?address1=7580%20Preservation%20Dr&address2=Sarasota%2C%20FL",
beforeSend: function (request) {
request.setRequestHeader("apikey", 'xxxxxxxxxxxxxxxxxxxx');
},
success: function (result) {
$.each(result, function (index, object) {
$.each(object, function (i, o) {
console.log(i + " = " + o);
})
})
},
error: function (xmlHttpRequest, textStatus, errorThrown) {
output = '<div class="error">' + textStatus + ' ' + errorThrown + '</div>';
}
});
However, I am only getting the following output.
version = 1.0.0
code = 0
msg = SuccessWithResult
total = 1
page = 1
pagesize = 10
0 = [object Object]
What I would like to do is be able to Get the property data so I can pull out specific key/values from the property node.
Any help would be greatly appreciated.
Upvotes: 0
Views: 961
Reputation: 333
I actually got what I needed using
console.log(result.property[0].address.oneLine)
console.log(result.property[0].location.latitude)
thanks for all the help who contributed.
Upvotes: 0
Reputation: 3551
"property" is an array itself so you'd need another iteration through there, and then a second iteration to scan the objects returned.
If you are trying to go after a specific property, there are easier ways. You can use result.property[0].area.munname;
To access a munname directly.
Upvotes: 1