解决hashmap通过key取不到value

解决hashmap通过key取不到value

HarmonyOS
2024-05-22 22:59:01
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
江湖骗子嗷

示例代码如下:

import HashMap from '@ohos.util.HashMap'; 
import http from '@ohos.net.http'; 
import { BusinessError } from '@ohos.base'; 
 
export class ConcatUsViewModel { 
  initData() { 
    this.queryHotLIne() 
  } 
 
  /** 
   * 服务热线查询 
   * @param siteCode 站点编码 
   * @param countryCode 国家编码 
   * @param langCode 语言编码 
   * @param offerCode 产品Offering Code 
   * @param hotlineType 热线类别 0标识VIP;1标识保时捷;2标识服务热线;3标识在线客服 为空时,默认查询“服务热线”类别 
   */ 
  private queryHotLIne() { 
    const body: Record<string, string> = { 
      "siteCode": "zh_CN", 
      "countryCode": "CN", 
      "hotlineType": "0,1,2,3,4,5,6", 
      "langCode": "zh-cn", 
      "offerCode": "OFFE00918115" 
    } 
 
    let httpRequest = http.createHttp(); 
    httpRequest.request( 
      "https://service-cn.hwccpc.com/ccpcmd/services/dispatch/secured/CCPC/EN/iRetail/getHotline/4000", 
      { 
        method: http.RequestMethod.POST, 
        header: [{ 
          'Content-Type': 'application/json' 
        }], 
        extraData: body, 
      }, (err: BusinessError, data: http.HttpResponse) => { 
      if (!err) { 
        console.info('Result11111111111111111111:' + JSON.stringify(data.result)); 
        httpRequest.destroy(); 
        let list: HotLineDetail[] = JSON.parse(data.result as string)?.responseData?.list 
        let hotLineMap = new HashMap<string, HotLineDetail>() 
        for (let i = 0; i < list.length; i++) { 
          const hotline = list[i]; 
          let index = hotline.hotlineType; 
          hotLineMap.set(index, hotline) 
        } 
        if (hotLineMap.get('2')) { 
          console.log('是否有值', hotLineMap.get('2')) 
        } 
      } 
    } 
    ) 
  } 
} 
 
export class HotLineDetail { 
  siteCode?: string; 
  hotlineType?: string; 
  phone?: string; 
  releasedWorld?: string; 
  releasedGlory?: string; 
  supportLanguage?: string; 
  serviceHours?: string; 
  businessHour?: string; 
  email?: string; 
  isRecommended?: string; 
  sort?: Number; 
  transLink?: string; 
  type?: string 
}
分享
微博
QQ
微信
回复
2024-05-23 17:17:01
相关问题
ResourceTable不到layout
11249浏览 • 3回复 待解决
dataPreferences.Preferences不到数据
233浏览 • 0回复 待解决
Key-Value存储问题咨询
309浏览 • 1回复 待解决
如何通过key获取对象值
351浏览 • 1回复 待解决
不到设备的UDID怎么解决
3695浏览 • 1回复 待解决
HarmonyOS使用HashMap崩溃
391浏览 • 1回复 待解决
router传递hashmap参数问题
1571浏览 • 1回复 待解决