json_key_test.go 904 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package test
  2. import (
  3. "Yunlot/lib"
  4. "encoding/json"
  5. "strings"
  6. "testing"
  7. )
  8. func Test_jsonkey(t *testing.T) {
  9. var data = `{
  10. "clientID": "869023065073597",
  11. "msgID": "24152",
  12. "msgID11": "1111",
  13. "msgID22": "1111",
  14. "msgID33": "3333",
  15. "AAAA": {
  16. "typeCode": "123",
  17. "typeCode2": "123",
  18. "AAAA": {
  19. "name": "TempSet",
  20. "value": "272"
  21. },
  22. "BBBB": [{
  23. "name": "TempSet",
  24. "value": "266666"
  25. }],
  26. "CCCC": [{
  27. "name": "TempSet",
  28. "value": "2766662"
  29. }]
  30. },
  31. "paramsb": {
  32. "typeCode": "123",
  33. "typeCode2": "123"
  34. },
  35. "paramslist": [{
  36. "typeCode": "123",
  37. "typeCode2": "123"
  38. }]
  39. }`
  40. var articleSlide map[string]interface{}
  41. err := json.Unmarshal([]byte(data), &articleSlide)
  42. if err != nil {
  43. }
  44. topicName := "/paramsb/"
  45. topicName = strings.Trim(topicName, "/")
  46. topicNameList := strings.Split(topicName, "/")
  47. x := lib.Json_key(topicNameList, 0, articleSlide)
  48. println(x)
  49. }