gjson_test.go 581 B

123456789101112131415161718192021222324252627282930313233343536
  1. package yu_json
  2. import "testing"
  3. func TestGet(t *testing.T) {
  4. json := `{
  5. "programmers": [
  6. {
  7. "firstName": "Janet",
  8. "lastName": "McLaughlin",
  9. }, {
  10. "firstName": "Elliotte",
  11. "lastName": "Hunter",
  12. }, {
  13. "firstName": "Jason",
  14. "lastName": "Harold",
  15. }
  16. ]
  17. }`
  18. value := Get(json, "name.last")
  19. println(value.String())
  20. value = Get(json, "programmers.#.lastName")
  21. println(value.String())
  22. for _, name := range value.Array() {
  23. println(name.String())
  24. }
  25. value = Get(json, "age")
  26. println(value.String())
  27. println(json)
  28. }