将json对象转换成可以适应markdown格式的展示效果。

举例数据:

const content = {
            "姓名": "zhangsan",
            "name": "shkahsdhsa",
            "2222": "22222"
          }

页面展示:

格式化后展示:

实现代码

const content = {
            "姓名": "zhangsan",
            "name": "shkahsdhsa",
            "2222": "22222"
          }
          const markdownContent = Object.entries(content)
            .map(([key, value]) => `    ${key}: ${value}`)
            .join('\n\n');
          const showStr = `{\n\n${markdownContent}\n\n}`
          

 

posted @ 2024-01-31 17:19  吾本人间一叶茶  阅读(388)  评论(0编辑  收藏  举报
Live2D