js中json与对象互转
发表于|更新于
|浏览量:
人生要有意义只有发扬生命,快乐就是发扬生命的最好方法。——张闻天
如题
首先是json字符串转对象
1 | JSON.parse("{\"id\":\"ddd\"\}") |
得到的结果就是对象啦

然后是对象转json字符串
1 | JSON.stringify({id:"ddd"}) |
非常简单

相关推荐
2020-10-24
js禁止右键点击事件
勤劳一日,可得一夜安眠;勤劳一生,可得幸福长眠。——达·芬奇 js禁止右键点击事件触发代码 123456789101112131415161718192021222324function click() { return false;}function click1() { if (event.button == 2) { return false; }}function CtrlKeyDown() { if (event.ctrlKey) { return false; }}document.onkeydown = CtrlKeyDown;document.onselectstart = click;document.onmousedown = click1;document.oncontextmenu = function(event) { if (document.all) windo...
2022-03-09
Array.prototype.fill()
新的方法和概念,常常比解决问题本身更重要。——华罗庚 我们在前端开发中,可以使用fill函数来快速构建数组 1Array(5).fill(1,1,4) 得到的是这样一个数组: 1[, 1, 1, 1, ] 这里参数fill(value,start,end)也是可以省略的 12345678910111213141516[1, 2, 3].fill(4); // [4, 4, 4][1, 2, 3].fill(4, 1); // [1, 4, 4][1, 2, 3].fill(4, 1, 2); // [1, 4, 3][1, 2, 3].fill(4, 1, 1); // [1, 2, 3][1, 2, 3].fill(4, 3, 3); // [1, 2, 3][1, 2, 3].fill(4, -3, -2); // [4, 2, 3][1, 2, 3].fill(4, NaN, NaN); // [1, 2, 3][1, 2, 3].fill(4, 3...
2023-08-21
vuepress2一次性获取所有frontmatter
上帝是孤独的,恶魔却总在拉帮结伙。——梭罗的《瓦尔登湖》。 接上文: vuepress获取所有页面frontmatter 这次是vuepressv2.0.0-beta.66 首页 | VuePress 核心代码: 12345678910// .vuepress/getAllFrontmatter.smodule.exports = { name: 'get-all-frontmatter', extendsPage: (page, app) => { console.log({ page, app }) console.log(page.data.frontmatter) app.siteData.frontmatter = app.siteData.frontmatter ?? [] app.siteData.frontmatter.push(page.data.frontmatter) },}; 然后配置: 123456789101112131415// ...
2022-12-15
低仿lusaxweb鼠标
幸福的婚姻生活,往往会被卑鄙的勾当、阴险的猜忌所破坏。——莎士比亚 这是 http://lusaxweb.net/ 它的鼠标很有意思,是一个圈,能够反色,我们低仿一个 代码如下: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263<!DOCTYPE html><html><head> <style> * { margin: 0; padding: 0; cursor: none; } .img { height: 80vh; width: 80vw; overflow: hidden; } .img:ho...
2023-03-28
vue-smooth-dnd
愤怒是由于别人的过错而惩罚自己——蒲柏 分享一个vue拖动组件 github:https://github.com/kutlugsahin/vue-smooth-dnd 在线Demo:https://kutlugsahin.github.io/vue-smooth-dnd/#/cards
2021-12-11
jq eq
要知道对好事的称颂过于夸大,也会招来人们的反感轻蔑和嫉妒。——培根 我们使用jquery选择器时如果有多个结果,我们可以使用eq函数选择指定下标的元素 例如此处 1234567891011121314151617<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title></title> <script src="https://www.jq22.com/jquery/jquery-3.3.1.js"></script> </head> <body> <div class="ruben">vampire</div> <div class="ruben">ruben</div> <script type="text/javascript"&...

阿超
我的名字叫阿超 年龄25岁 家在北京市 职业是软件开发 每天最晚也会在八点前回家 不抽烟 酒浅尝辄止 晚上十二点上床 保证睡足八个小时 睡前写一篇博客 再做二十分钟俯卧撑暖身 然后再睡觉 基本能熟睡到天亮 像婴儿一样不留下任何疲劳和压力 就这样迎来第二天的早晨 健康检查结果也显示我很正常 我想说明我是一个不论何时都追求内心平稳的人 不拘泥于胜负 不纠结于烦恼 不树立使我夜不能寐的敌人 这就是我在这社会的生活态度
Follow Me公告
This is my Blog