You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何处理node-zillow的GetSearchResults()返回结果?

解析Zillow GetSearchResults响应提取信息

Got it, let's break this down step by step! The result array in your response is where all the property details live—each item in the array is an object packed with the data you need. Here's how to pull out what you want:

1. 先定位到结果数组

首先你需要从响应结构里钻取到result数组。假设你把完整的API响应存在了zillowResponse变量里:

// 获取房产结果数组
const propertyResults = zillowResponse.response.results.result;

2. 检查结果并提取数据

因为是数组,可能会有多个匹配你搜索条件的房产。你可以遍历所有结果,或者直接取第一个(搜索具体地址时最常用)。

示例:提取核心房产信息

下面是一段完整代码,用来提取地址、Zestimate估值、卧室数量等常见字段:

// 你从GetSearchResults拿到的原始响应
const zillowResponse = { 
  request: { address: '113 Cherry St', citystatezip: 'Seattle, Washington' }, 
  message: { text: 'Request successfully processed', code: '0' }, 
  response: { results: { result: [Array] } } 
};

// 获取结果数组
const propertyResults = zillowResponse.response.results.result;

// 先确认数组里有内容
if (propertyResults && propertyResults.length > 0) {
  // 取第一个匹配的房产(如果需要所有结果,用forEach循环遍历即可)
  const targetProperty = propertyResults[0];

  // 把需要的信息提取到一个简洁的对象里
  const extractedPropertyInfo = {
    fullAddress: `${targetProperty.address.street}, ${targetProperty.address.city}, ${targetProperty.address.state} ${targetProperty.address.zipcode}`,
    zestimate: targetProperty.zestimate.amount._,
    bedroomCount: targetProperty.bedrooms,
    bathroomCount: targetProperty.bathrooms,
    squareFootage: targetProperty.finishedSqFt,
    propertyType: targetProperty.useCode
  };

  console.log('提取到的房产信息:', extractedPropertyInfo);
} else {
  console.log('没有找到匹配的房产结果');
}

3. 查看所有可用字段

如果你不确定result对象里还有哪些字段,可以格式化打印整个数组来查看全部内容:

// 格式化打印结果,方便查看所有字段
console.log(JSON.stringify(propertyResults, null, 2));

这样你就能看到所有嵌套字段,比如税务记录、物业细节或者其他估值数据。


内容的提问来源于stack exchange,提问作者user9210794

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:52:03