HarmonyOS 怎么解析集合对象和解析jsonarray的

HarmonyOS
2024-12-27 15:45:53
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280

可参考以下代码:

export interface IShopDetailResult {
  categoryId : string
  description : string
  detail : string[]
  id : string
  images : string[]
  price : Number
  promotion : string
  specifications : string[]
  title : string
  imagesResource : Resource
}
export class ShopDetailResult implements IShopDetailResult {
  categoryId: string = ""
  description: string = ""
  detail: string[] = [""]
  id: string = ""
  images: string[] = [""]
  price: Number = 0
  promotion: string = ""
  specifications: string[] = [""]
  title: string = ""
  imagesResource : Resource
  constructor(props: ShopDetailResult) {
    this.categoryId = props.categoryId;
    this.description = props.description;
    this.detail = props.detail;
    this.id = props.id;
    this.images = props.images;
    this.price = props.price;
    this.promotion = props.promotion;
    this.specifications = props.specifications;
    this.title = props.title;
    this.imagesResource = props.imagesResource;
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.

以上是class类实现接口

let shopListResult = JSON.parse(JSON.stringify(shopList)) as Array<IShopDetailResult> 
  • 1.

这一步JSON.stringify(shopList)就是相当于json数据,as Array<IShopDetailResult>就是要转换的数组,这是转换的方式。同理,转换class成json的,JSON.stringify(shopList) as string,按照这样的转换方式即可。这个转换需要您参考jsonarray的json数据,自己建立class进行转换。另外,ArrayList并不是原生的类型,通常使用数组(Array)来代替 ArrayList。

分享
微博
QQ
微信
回复
2024-12-27 17:05:47
相关问题
证书解析解析证书CN怎么获取
1224浏览 • 1回复 待解决
HarmonyOS Jsons解析对象无法调用防范
1382浏览 • 1回复 待解决
json解析对象后获取数据返回undefined。
1800浏览 • 1回复 待解决
HarmonyOS 怎么解析本地文件json内容?
923浏览 • 1回复 待解决
HarmonyOS url里字符串怎么解析
644浏览 • 1回复 待解决
HarmonyOS json 解析
785浏览 • 1回复 待解决
HarmonyOS 数据解析
940浏览 • 1回复 待解决
HarmonyOS AES解析失败
493浏览 • 1回复 待解决
json如何在ArkTS中解析到Array对象中?
1029浏览 • 2回复 待解决
HarmonyOS Map解析
585浏览 • 0回复 待解决
HarmonyOS uri解析问题
519浏览 • 1回复 待解决
HarmonyOS json解析问题
1172浏览 • 1回复 待解决
Text怎么解析展示带html标签文本?
2862浏览 • 1回复 待解决
HarmonyOS xml解析失败
618浏览 • 1回复 待解决
HarmonyOS xml解析异常
778浏览 • 1回复 待解决
HarmonyOS 地址解析问题
735浏览 • 1回复 待解决