当前位置: 首页 > news >正文

中国电子商务网站建设情况婚纱销售网站

中国电子商务网站建设情况,婚纱销售网站,深圳网站推广活动方案,wordpress跳转链接404GJSON 是一个 Go 包#xff0c;它提供了一种快速而简单的方法来从 json 文档获取值。它具有单行搜索、点符号路径、迭代和解析 json 行等功能。 GJSON 也可用于Python和Rust 入门 安装中 要开始使用GJSON 请安装 Go 并运行 go get #xff1a; $ go get -u github.com/ti… GJSON 是一个 Go 包它提供了一种快速而简单的方法来从 json 文档获取值。它具有单行搜索、点符号路径、迭代和解析 json 行等功能。 GJSON 也可用于Python和Rust 入门 安装中 要开始使用GJSON 请安装 Go 并运行 go get $ go get -u github.com/tidwall/gjson获取一个值 获取json中搜索指定路径。路径采用点语法例如“name.last”或“age”。当找到该值时它会立即返回。 package mainimport github.com/tidwall/gjsonconst json {name:{first:Janet,last:Prichard},age:47}func main() {value : gjson.Get(json, name.last)println(value.String()) }这将打印 Prichard还有用于一次获取多个值的GetMany函数以及用于处理 JSON 字节切片的GetBytes 。 路径语法 下面是路径语法的快速概述有关更完整的信息请查看 GJSON 语法。 路径是一系列由点分隔的键。键可以特殊通配符“*”和“?”。要访问集群中的元素数请使用索引作为键。要获取集群中的元素数或访问子路径请使用“# ”字符。点和通配符可以用“\”转义。 {name: {first: Tom, last: Anderson},age:37,children: [Sara,Alex,Jack],fav.movie: Deer Hunter,friends: [{first: Dale, last: Murphy, age: 44, nets: [ig, fb, tw]},{first: Roger, last: Craig, age: 68, nets: [fb, tw]},{first: Jane, last: Murphy, age: 47, nets: [ig, tw]}] }name.last Anderson age 37 children [Sara,Alex,Jack] children.# 3 children.1 Alex child*.2 Jack c?ildren.0 Sara fav\.movie Deer Hunter friends.#.first [Dale,Roger,Jane] friends.1.last Craig您还可以使用查询数据库中的第一个匹配项#(...)或使用查找所有匹配项#(...)#。查询支持、!、、、、 比较仿真以及简单模式匹配%like和!% not like。 friends.#(lastMurphy).first Dale friends.#(lastMurphy)#.first [Dale,Jane] friends.#(age45)#.last [Craig,Murphy] friends.#(first%D*).last Murphy friends.#(first!%D*).last Craig friends.#(nets.#(fb))#.first [Dale,Roger]请注意在 v1.3.0 之前查询使用#[…]逗号。这在 v1.3.0 中进行了更改小区与新的 多路径语法不一致。为了兼容 #[…]将继续工作直到下一个主要版本。 结果类型 GJSON 支持 json 类型string、number、bool和null。恢复和恢复对象原始 json 类型返回。 该Result类型包含以下之一 bool, for JSON booleans float64, for JSON numbers string, for JSON string literals nil, for JSON null直接访问该值 result.Type // can be String, Number, True, False, Null, or JSON result.Str // holds the string result.Num // holds the float64 number result.Raw // holds the raw json result.Index // index of raw value in original json, zero means index unknown result.Indexes // indexes of all the elements that match on a path containing the # query character.有多种方便的函数可以处理结果 result.Exists() bool result.Value() interface{} result.Int() int64 result.Uint() uint64 result.Float() float64 result.String() string result.Bool() bool result.Time() time.Time result.Array() []gjson.Result result.Map() map[string]gjson.Result result.Get(path string) Result result.ForEach(iterator func(key, value Result) bool) result.Less(token Result, caseSensitive bool) bool该result.Value()函数返回一个interface{}需要类型断言的并且是以下 Go 类型之一 boolean bool number float64 string string null nil array []interface{} object map[string]interface{}该result.Array()函数返回一个值数据库。如果结果表示不存在的值则将返回一个空数据库。如果结果不是 JSON 数据库则返回值将是支持一个结果的数据库。 64位整数 和调用能够读取所有64位从而允许使用大型JSON整数result.Int()。result.Uint() result.Int() int64 // -9223372036854775808 to 9223372036854775807 result.Uint() uint64 // 0 to 18446744073709551615简单解析并获取 有一个Parse(json)函数可以执行简单的解析然后result.Get(path)结果搜索。 例如所有这些都会返回相同的结果 gjson.Parse(json).Get(name).Get(last) gjson.Get(json, name).Get(last) gjson.Get(json, name.last)检查值是否存在 有时您只是想知道某个值是否存在。 value : gjson.Get(json, name.last) if !value.Exists() {println(no last name) } else {println(value.String()) }// Or as one step if gjson.Get(json, name.last).Exists() {println(has a last name) }验证 JSON 并且Get函数Parse期望 json 格式良好。错误的 json 不会恐慌但可能会返回意外的结果。 如果您从不可预测的来源使用 JSON那么您可能需要在使用 GJSON 之前进行验证。 if !gjson.Valid(json) {return errors.New(invalid json) } value : gjson.Get(json, name.last)解析到Map 解组为map[string]interface{} m, ok : gjson.Parse(json).Value().(map[string]interface{}) if !ok {// not a map }解析使用[]byte 如果您的 JSON 包含在[]byte切片中则可以使用GetBytes函数。这比Get(string(data), path)。 var json []byte ... result : gjson.GetBytes(json, path)如果您正在使用该gjson.GetBytes(json, path)函数并且希望避免转换result.Raw为 a []byte那么您可以使用以下模式 var json []byte ... result : gjson.GetBytes(json, path) var raw []byte if result.Index 0 {raw json[result.Index:result.Indexlen(result.Raw)] } else {raw []byte(result.Raw) }这是原始 json 的消耗而得到的无分配子切片。该方法利用了result.Index字段该字段是原始数据在原始 json 中的位置。的值可能result.Index为零在这种情况下result.Raw会转换为[]byte。 一次获得多个值 该GetMany函数可用于同时获取多个值。 results : gjson.GetMany(json, name.first, name.last, age)返回值是 a []Result将始终包含与输入路径两个数量的项目。
http://www.pierceye.com/news/722455/

相关文章:

  • 万网个人网站备案查询甘肃建设银行网站
  • 网站建设有什么费用wordpress国外主题网站
  • 手机网站下拉菜单代码com域名代表什么
  • 网站右侧信息跟随左侧菜单栏变化好牛网站建设
  • 手机网站pc网站免费国外服务器租用
  • 商城网站建设服务wordpress手机导航三横拦
  • app设计欣赏网站长沙制作公园仿竹护栏
  • 景泰县做网站网站建设上市
  • 电子商务网站开发课题简介php mysql网站开发...
  • 如何提升网站alexa排名wordpress加联系方式
  • 餐厅网站模版wordpress linux
  • 网站seo优化怎么做mes系统
  • 江津网站建设公司做外贸去哪个网站找客户
  • 网站建设-部署与发布wordpress怎么代码高亮
  • 自己做的网站本地虚拟上传wordpress 不能评论
  • 百度贴吧网站开发需求分析怎么免费自己做推广
  • 网站怎么访问自己做的网页中国园林网
  • 郑州服装网站建设做营销型网站用那个cms好
  • 网站登录页面模板下载wordpress添加随机图片
  • 贵阳网站建设哪家便宜关键词林俊杰mp3在线听
  • 怎么看网站是哪个系统做的怎么自己建网站赚钱
  • 茶叶建设网站的优势小学网站模板
  • 铜川免费做网站公司个人博客页面
  • 织梦网站安装出现404 not found商务网站设计素材
  • 石家庄seo网站排名合肥做网站价格
  • 盘锦市城乡建设厅网站区域代理加盟项目
  • 源码如何做网站个人音乐网站源码搭建
  • 网站推广资讯网站注册界面设计
  • 凡网站建设网站线下推广怎么做
  • 简要描述创建商务站点的商务镇江海绵城市建设官方网站