关于鸿蒙arkts解析json字符串问题

首先声明喔是小白,但是这个问题已经困扰我很久了,找了很多的资料,看了很多视频,都没能解决,一直卡在这里

同一段字符串,在typescript中运行是正常的,但是在arkts上面运行就是空,求解大神帮忙分析是什么问题

下面是本来的代码,就是简单的处理json字符串

  let str='{"code":1,"msg":"\u6570\u636e\u5217\u8868","page":1,"pagecount":3116,"limit":20,"total":62316,"list":[{"vod_id":"61295","vod_name":"\u4f9d\u5170\u7070\u70ec","type_id":"17","type_name":"\u6cf0\u56fd\u5267","vod_en":"yilanhuijin","vod_time":"2024-12-31 16:06:01","vod_remarks":"\u66f4\u65b0\u81f316\u96c6","vod_play_from":"1080zyk"}]}'
  let obj=JSON.parse(str) as object
  console.log(obj['msg'])

我在DevEco Studio上面的代码是这样子的

export function dataManager(){
  let str='{"code":1,"msg":"\u6570\u636e\u5217\u8868","page":1,"pagecount":3116,"limit":20,"total":62316,"list":[{"vod_id":"61295","vod_name":"\u4f9d\u5170\u7070\u70ec","type_id":"17","type_name":"\u6cf0\u56fd\u5267","vod_en":"yilanhuijin","vod_time":"2024-12-31 16:06:01","vod_remarks":"\u66f4\u65b0\u81f316\u96c6","vod_play_from":"1080zyk"}]}'
  let obj=JSON.parse(str) as object
  console.log(obj['msg'])
  return "333"
}

但是运行结果是

01-01 09:37:37.557   26672-21324   A0c0d0/JSAPP                                          W     The json.parse interface in the Previewer is a mocked implementation and may behave differently than on a real device.
01-01 09:37:37.557   26672-21324   A0c0d0/JSAPP                                          I     undefined
01-01 09:38:17.327   26672-21324   A0c0d0/JSAPP                                          W     The json.parse interface in the Previewer is a mocked implementation and may behave differently than on a real device.
01-01 09:38:17.327   26672-21324   A0c0d0/JSAPP                                          I     undefined
01-01 09:38:41.391   3428-28256    A0c0d0/JSAPP                                          W     The json.parse interface in the Previewer is a mocked implementation and may behave differently than on a real device.
01-01 09:38:41.391   3428-28256    A0c0d0/JSAPP                                          I     undefined

我试着去定义接口

import { JSON } from '@kit.ArkTS';

interface vodDataInterface{
  vod_id: string;
  vod_name: string;
  vod_remarks?: string;
  vod_play_from?: string;
  vod_play_url: string;
  vod_actors?: string;
  vod_director?: string;
  vod_area?: string;
  vod_year?: string;
  vod_class?: string;
  vod_duration?: string;
  vod_content?: string;
  vod_pic?: string;
  vod_score?: string;
  vod_play_note?: string;
  vod_type?: string;
  vod_status?: string;
}

interface httpDataInterface{
  code: number;
  msg: string;
  page: number;
  pagecount: number;
  limit: number;
  total: number;
  list: Array<vodDataInterface>
}

export function dataManager(){
  let str='{"code":1,"msg":"\u6570\u636e\u5217\u8868","page":1,"pagecount":3116,"limit":20,"total":62316,"list":[{"vod_id":"61295","vod_name":"\u4f9d\u5170\u7070\u70ec","type_id":"17","type_name":"\u6cf0\u56fd\u5267","vod_en":"yilanhuijin","vod_time":"2024-12-31 16:06:01","vod_remarks":"\u66f4\u65b0\u81f316\u96c6","vod_play_from":"1080zyk"}]}'
  let obj=JSON.parse(str) as httpDataInterface
  console.log(obj.msg)
  return "333"
}

运行结果仍然是

01-01 09:54:00.245   17252-19888   A0c0d0/JSAPP                                          W     The json.parse interface in the Previewer is a mocked implementation and may behave differently than on a real device.
01-01 09:54:00.245   17252-19888   A0c0d0/JSAPP                                          I     undefined


但是在typescript中运行是正常的


关于鸿蒙arkts解析json字符串问题-鸿蒙开发者社区


到底是为什么呀,话说arkts不是typescript的超集吗?求大神帮忙分析一下

arkts
harmonyOS NEXT
json
3天前
浏览
收藏 0
回答 0
待解决
相关问题
嵌套JSON字符串解析问题
2124浏览 • 1回复 待解决
HarmonyOS 超长JSON字符串解析
153浏览 • 1回复 待解决
如何解析JSON字符串
1369浏览 • 1回复 待解决
HarmonyOS 如何解析json字符串
699浏览 • 1回复 待解决
HarmonyOS 服务端JSON字符串解析问题
660浏览 • 1回复 待解决
关于加密字符串相关问题
277浏览 • 1回复 待解决
如何打印JSON对象和JSON字符串
461浏览 • 1回复 待解决
HarmonyOS url里的字符串怎么解析
78浏览 • 1回复 待解决
如何实现Map转JSON字符串
1210浏览 • 1回复 待解决
HarmonyOS字符串替换问题
980浏览 • 1回复 待解决
如何将对象转为JSON字符串
674浏览 • 1回复 待解决
关于字符串的分割和重组处理
4628浏览 • 1回复 待解决
HarmonyOS 字符串编码问题
162浏览 • 1回复 待解决
HarmonyOS 替换字符串问题
191浏览 • 1回复 待解决
HarmonyOS string字符串截取问题
80浏览 • 1回复 待解决
HarmonyOS $r 字符串替换问题
1060浏览 • 1回复 待解决
如何将JSON字符串转为Map
433浏览 • 1回复 待解决
HarmonyOS 读取本地json文件转成字符串
124浏览 • 1回复 待解决
HarmonyOS ArkTS里面字符串怎么换行
111浏览 • 1回复 待解决