亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JavaScript 將包含代碼的字符串轉換為對象

JavaScript 將包含代碼的字符串轉換為對象

弒天下 2023-11-12 14:58:53
在我當前的項目中,我有一個variables.js,其中包含主題顏色等所有變量。我想將這個完整的 Variables.js 放入數據庫中,但它很長,我更愿意將其作為字符串放入數據庫中,以便于后續更改。有什么方法可以使這個看起來像下面的示例的字符串轉換成一個與下面的示例完全一樣的對象。這是變量.js 內部的示例export default {    faq_size                          : 5,    debug_show_php_errors             : true,    debug_disable_captcha             : false,    discord_color                     : "#7289DA",    theme                             : {primary: "deep-purple darken-4", secondary: "deep-purple accent-1",},    currencies                        : ["€", "$", "?", "£", "¥"],    languages                         : [        {            lang   : 'en',            code   : 'US',            country: 'English',        },        {            lang   : 'de',            code   : 'DE',            country: 'Deutsch',        }    ],}
查看完整描述

1 回答

?
繁華開滿天機

TA貢獻1816條經驗 獲得超4個贊

import data from 'variables.js'


// convert data to string 

let dataInStringFormat = JSON.stringify(data);

// now you can save this in any database you want.


// convert string to object again

let data = JSON.parse(dataInStringFormat);


查看完整回答
反對 回復 2023-11-12
  • 1 回答
  • 0 關注
  • 185 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號