node内置模块-URL
2021-02-11 08:16
标签:pre detail https OLE path prot host object class node内置模块-URL 标签:pre detail https OLE path prot host object class 原文地址:https://www.cnblogs.com/catherLee/p/13042697.htmlurl 类比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