url 類比json 記憶
url.parse 將url字符串轉成對象
url.format將url 對象轉字符串
const url=require('url')
let urlString='https:47.95.207.1:3000/fcj/recommend/hot/hehe?us=123&ps=567#nihao' let urlObj=url.parse(urlString) console.log(urlObj)
let obj= { protocol: 'https:', slashes: null, auth: null, host: null, port: null, hostname: null, hash: '#nihao', search: '?us=123&ps=567', query: 'us=123&ps=567', pathname: '47.95.207.1:3000/fcj/recommend/hot/hehe', path: '47.95.207.1:3000/fcj/recommend/hot/hehe?us=123&ps=567', href: 'https:47.95.207.1:3000/fcj/recommend/hot/hehe?us=123&ps=567#nihao' } let string=url.format(obj) console.log(string)
🌲 回憶:什麼是JSON,什麼是JSON對象,什麼是JSON字符串
JSON( JavaScript Object Notation):是一種數據格式。
JSON對象,是JSON格式的對象。JSON字符串,是JSON格式的字符串。
參考:https://blog.csdn.net/u011240877/article/details/46651249