码迷,mamicode.com
首页 > Web开发 > 详细

node内置模块-URL

时间:2020-06-04 13:28:05      阅读:92      评论:0      收藏:0      [点我收藏+]

标签:pre   detail   https   OLE   path   prot   host   object   class   

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




node内置模块-URL

标签:pre   detail   https   OLE   path   prot   host   object   class   

原文地址:https://www.cnblogs.com/catherLee/p/13042697.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!