前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >爬虫+反爬虫+js代码混淆

爬虫+反爬虫+js代码混淆

作者头像
李昂君
发布2022-11-25 09:23:32
5.4K0
发布2022-11-25 09:23:32
举报
文章被收录于专栏:李昂君

Description

A compression algorithm for JSON

gjsonpack is a GoLang program to pack and unpack JSON data.

It can compress to 55% of original size if the data has a recursive structure.

take JavaScript transformation to GoLang, source repositories please see.

Repositories URL

github: https://github.com/JoiLa/gjsonpack/

How to use?

代码语言:javascript
复制
go get github.com/JoiLa/gjsonpack

How to usHow to compress json

代码语言:javascript
复制
// big JSON
var basicJSON = `{
    "type": "world",
    "name": "earth",
    "children": [
        {
            "type": "continent",
            "name": "America",
            "children": [
                {
                    "type": "country",
                    "name": "Chile",
                    "children": [
                        {
                            "type": "commune",
                            "name": "Antofagasta"
                        }
                    ]
                }
            ]
        },
        {
            "type": "continent",
            "name": "Europe"
        }
    ]
}`

jsonMap := make(map[string]interface{}, 0)
if err := json.Unmarshal([]byte(basicJSON), &jsonMap); err != nil {
    t.Fatal(err)
}

// pack the big JSON 
packStr, packErr := Pack(jsonMap)
if packErr != nil {
    fmt.Fprintln(packErr)
}
fmt.Println("packStr:", packStr)
// packStr: type|world|name|earth|children|continent|America|country|Chile|commune|Antofagasta|Europe^^^$0|1|2|3|4|@$0|5|2|6|4|@$0|7|2|8|4|@$0|9|2|A]]]]]|$0|5|2|B]]]

// do something with the packed JSON

How to decompress json

代码语言:javascript
复制
packStr:="type|world|name|earth|children|continent|America|country|Chile|commune|Antofagasta|Europe^^^$0|1|2|3|4|@$0|5|2|6|4|@$0|7|2|8|4|@$0|9|2|A]]]]]|$0|5|2|B]]]"
jsonMap := make(map[string]interface{}, 0)
unPackErr := Unpack(packStr, &jsonMap)
if unPackErr != nil {
    return
}
fmt.Printf("jsonMap:%v\n", jsonMap)
// jsonMap:map[children:[map[children:[map[children:[map[name:Antofagasta type:commune]] name:Chile type:country]] name:America type:continent] map[name:Europe type:continent]] name:earth type:world]

// do something with the unPacked JSON
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-11-19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Description
  • Repositories URL
  • How to use?
  • How to usHow to compress json
  • How to decompress json
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档