zoukankan      html  css  js  c++  java
  • JSON parse \n bug All In One

    JSON parse \n bug All In One

    const obj = {str: "\n\ntext"};
    // {str: '\n\ntext'}
    
    const str = JSON.stringify(obj);
    // '{"str":"\\n\\ntext"}'
    
    const result = JSON.parse(str);
    // {str: '\n\ntext'}
    
    

    处理 \n bug

    接口数据问题

    material_content: "{\"pc\":[],\"mobile\":[{\"id\":\"261916\",\"type\":\"simple-text\",\"name\":\"简单文本\",\"preview\":\"/assets/add-simple-text.jpg\",\"classNames\":[],\"props\":{\"width\":375,\"height\":600,\"left\":0,\"top\":0,\"zIndex\":100,\"aspectRatio\":false,\"text\":\"\n\n\n\nworjd\",\"font\":{\"color\":\"#C53636\",\"family\":\"\",\"size\":\"58\",\"bold\":true},\"gradient\":false,\"textAlign\":\"center\",\"letterSpacing\":0,\"lineHeight\":1}}]}"
    
    
    {
      "name": "wenbenjkuang012",
      "game_id": 10043,
      "region_id": null,
      "thum_url": "https://adpage.lilithcdn.com/online_dragonfly/1638253043_wenbenjkuang012_1638253043.0.jpeg",
      "material_content": "{\"pc\":[],\"mobile\":[{\"id\":\"261916\",\"type\":\"simple-text\",\"name\":\"简单文本\",\"preview\":\"/assets/add-simple-text.jpg\",\"classNames\":[],\"props\":{\"width\":375,\"height\":600,\"left\":0,\"top\":0,\"zIndex\":100,\"aspectRatio\":false,\"text\":\"\n\n\n\nworjd\",\"font\":{\"color\":\"#C53636\",\"family\":\"\",\"size\":\"58\",\"bold\":true},\"gradient\":false,\"textAlign\":\"center\",\"letterSpacing\":0,\"lineHeight\":1}}]}",
      "is_used": 0,
      "id": 95,
      "user_name": "Eric",
      "note": "wenbenjkuang012"
    }
    
    

    OK

    material_content: "{\"pc\":[],\"mobile\":[{\"id\":\"261916\",\"type\":\"simple-text\",\"name\":\"简单文本\",\"preview\":\"/assets/add-simple-text.jpg\",\"classNames\":[],\"props\":{\"width\":375,\"height\":600,\"left\":0,\"top\":0,\"zIndex\":100,\"aspectRatio\":false,\"text\":\"\\n\\n\\n\\nworjd\",\"font\":{\"color\":\"#C53636\",\"family\":\"\",\"size\":\"58\",\"bold\":true},\"gradient\":false,\"textAlign\":\"center\",\"letterSpacing\":0,\"lineHeight\":1}}]}"
    
    

    refs



    ©xgqfrms 2012-2020

    www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

    原创文章,版权所有©️xgqfrms, 禁止转载 ️,侵权必究⚠️!


    xgqfrms
  • 相关阅读:
    CSS+JS实现兼容性很好的无限级下拉菜单
    自动切换的JS菜单
    (2)C#连sqlite
    protobuf编译器
    (67) c# 序列化
    (66) c# async await
    (65)C# 任务
    mbatis 入门
    (64)C# 预处理器指令
    (63)C# 不安全代码unsafe
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/15627157.html
Copyright © 2011-2022 走看看