解决hashmap通过key取不到value

解决hashmap通过key取不到value

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

示例代码如下:

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
9782浏览 • 3回复 待解决
不到设备的UDID怎么解决
1899浏览 • 1回复 待解决
arkts侧hashmap转为native侧
404浏览 • 1回复 待解决
router传递hashmap参数问题
352浏览 • 1回复 待解决
如何将Map/HashMap转为Object对象?
439浏览 • 1回复 待解决
如何找出Redis中的大Key与热Key
1496浏览 • 1回复 待解决
鸿蒙系统-如何拉联系人设置页面
16606浏览 • 1回复 待解决
如何实现ArkTS与C/C++的HashMap转换?
361浏览 • 0回复 待解决