forked from go/golangs_learn
VIVIMAN
3 years ago
5 changed files with 126 additions and 1 deletions
@ -0,0 +1,56 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"github.com/tidwall/gjson" |
|||
"log" |
|||
) |
|||
|
|||
func main() { |
|||
log.Print("查询内容:", gjson.Get(jsonStr, "code")) |
|||
log.Print("查询内容:", gjson.Get(jsonStr, "data.ext")) |
|||
log.Print("查询内容:", gjson.Get(jsonStr, "data.items.0")) |
|||
log.Print("查询内容:", gjson.Get(jsonStr, "data.items.2.resourceId")) |
|||
} |
|||
|
|||
var jsonStr = `{ |
|||
"code": 200, |
|||
"data": { |
|||
"ext": { |
|||
"utm_medium": "AAAA" |
|||
}, |
|||
"size": 6, |
|||
"items": [ |
|||
{ |
|||
"ext": null, |
|||
"resourceId": "1", |
|||
"mediaAssetInfo": null, |
|||
}, |
|||
{ |
|||
"ext": null, |
|||
"resourceId": "2", |
|||
"mediaAssetInfo": null, |
|||
}, |
|||
{ |
|||
"ext": null, |
|||
"resourceId": "3", |
|||
"mediaAssetInfo": null, |
|||
}, |
|||
{ |
|||
"ext": null, |
|||
"resourceId": "4", |
|||
"mediaAssetInfo": null, |
|||
}, |
|||
{ |
|||
"ext": null, |
|||
"resourceId": "5", |
|||
"mediaAssetInfo": null, |
|||
}, |
|||
{ |
|||
"ext": null, |
|||
"resourceId": "6", |
|||
"mediaAssetInfo": null, |
|||
} |
|||
] |
|||
}, |
|||
"message": "success" |
|||
}` |
@ -0,0 +1,58 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"github.com/tidwall/sjson" |
|||
"log" |
|||
) |
|||
|
|||
func main() { |
|||
res, err := sjson.Set(jsonStr, "code", "111") |
|||
if err != nil { |
|||
log.Fatal("发生异常:", err) |
|||
return |
|||
} |
|||
log.Print("查询内容:", res, jsonStr) |
|||
} |
|||
|
|||
var jsonStr = `{ |
|||
"code": 200, |
|||
"data": { |
|||
"ext": { |
|||
"utm_medium": "AAAA" |
|||
}, |
|||
"size": 6, |
|||
"items": [ |
|||
{ |
|||
"ext": null, |
|||
"resourceId": "", |
|||
"mediaAssetInfo": null, |
|||
}, |
|||
{ |
|||
"ext": null, |
|||
"resourceId": "", |
|||
"mediaAssetInfo": null, |
|||
}, |
|||
{ |
|||
"ext": null, |
|||
"resourceId": "", |
|||
"mediaAssetInfo": null, |
|||
}, |
|||
{ |
|||
"ext": null, |
|||
"resourceId": "", |
|||
"mediaAssetInfo": null, |
|||
}, |
|||
{ |
|||
"ext": null, |
|||
"resourceId": "", |
|||
"mediaAssetInfo": null, |
|||
}, |
|||
{ |
|||
"ext": null, |
|||
"resourceId": "", |
|||
"mediaAssetInfo": null, |
|||
} |
|||
] |
|||
}, |
|||
"message": "success" |
|||
}` |
Loading…
Reference in new issue