golang解析json数据

栏目: Go · 发布时间: 7年前

内容简介:golang官方包encoding/json包解析json数据太复杂,这里使用简单的json解析包simplejson。包的获取:go get github.com/bitly/go-simplejson就可以了

golang官方包encoding/json包解析json数据太复杂,这里使用简单的json解析包simplejson。

包的获取:go get github.com/bitly/go-simplejson就可以了

package main

import (
    "fmt"
  "github.com/bitly/go-simplejson"
  "bytes"
)
func main() {
    str := `{"name":"archmage","position":"beijing","data":[{"ip":1,"num":11},{"ip":2,"num":22}]}`
    buf :=bytes.NewBuffer([]byte(str))
    js,_:=simplejson.NewFromReader(buf)
    fmt.Println(js.Get("name").String())
    
    res,_:= simplejson.NewJson([]byte(str))
    fmt.Println(res.Get("name").String())
}

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Algorithms Unlocked

Algorithms Unlocked

Thomas H. Cormen / The MIT Press / 2013-3-1 / USD 25.00

Have you ever wondered how your GPS can find the fastest way to your destination, selecting one route from seemingly countless possibilities in mere seconds? How your credit card account number is pro......一起来看看 《Algorithms Unlocked》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具