weixin_57808501 2022-05-09 13:30 采纳率: 47.4%
浏览 60
已结题

字符串里面是数组格式 ,怎么转成数组

问题遇到的现象和发生背景

"[{file_property:2,tenant_id_:-1,history_type:00,suffix:txt,dir_path:\\enterprise\\few,update_time:2022-04-27 19:09:54,file_type:2,can_delete:1,id:203,full_path:\\enterprise\\few\\新建文本文档.txt,if_upload:1,creator:1,create_time:2021-11-18 02:44:05,file_name:新建文本文档.txt,if_root:0,dir_id:200,deleted:0,size:0}]"

想要的效果:
[{file_property:2,tenant_id_:-1,history_type:00,suffix:txt,dir_path:\\enterprise\\few,update_time:2022-04-27 19:09:54,file_type:2,can_delete:1,id:203,full_path:\\enterprise\\few\\新建文本文档.txt,if_upload:1,creator:1,create_time:2021-11-18 02:44:05,file_name:新建文本文档.txt,if_root:0,dir_id:200,deleted:0,size:0}]

  • 写回答

4条回答 默认 最新

  • 小蓝阿姨 2022-05-09 14:05
    关注
    const mData = '[{file_property:2,tenant_id_:-1,history_type:00,suffix:txt,dir_path:\\enterprise\\few,update_time:2022-04-27 19:09:54,file_type:2,can_delete:1,id:203,full_path:\\enterprise\\few\\新建文本文档.txt,if_upload:1,creator:1,create_time:2021-11-18 02:44:05,file_name:新建文本文档.txt,if_root:0,dir_id:200,deleted:0,size:0}]'
    function parseObject(str) {
        const mObject = {}
        Array.from(mData.matchAll(/(\w.*?):(.*?)[,|}]/g)).forEach(item => mObject[item[1]] = item[2])
        return [mObject]
    }
    console.log(parseObject(mData))
    

    img

    简单好理解,请采纳,谢谢

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 5月23日
  • 已采纳回答 5月23日
  • 创建了问题 5月9日

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站