gjson_deprecated.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Copyright GoFrame Author(https://github.com/gogf/gf). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package gjson
  7. import "github.com/gogf/gf/util/gconv"
  8. // ToMap converts current Json object to map[string]interface{}.
  9. // It returns nil if fails.
  10. // Deprecated, use Map instead.
  11. func (j *Json) ToMap() map[string]interface{} {
  12. j.mu.RLock()
  13. defer j.mu.RUnlock()
  14. return gconv.Map(*(j.p))
  15. }
  16. // ToArray converts current Json object to []interface{}.
  17. // It returns nil if fails.
  18. // Deprecated, use Array instead.
  19. func (j *Json) ToArray() []interface{} {
  20. j.mu.RLock()
  21. defer j.mu.RUnlock()
  22. return gconv.Interfaces(*(j.p))
  23. }
  24. // ToStruct converts current Json object to specified object.
  25. // The <pointer> should be a pointer type of *struct.
  26. // Deprecated, use Struct instead.
  27. func (j *Json) ToStruct(pointer interface{}, mapping ...map[string]string) error {
  28. j.mu.RLock()
  29. defer j.mu.RUnlock()
  30. return gconv.Struct(*(j.p), pointer, mapping...)
  31. }
  32. // ToStructDeep converts current Json object to specified object recursively.
  33. // The <pointer> should be a pointer type of *struct.
  34. // Deprecated, use Struct instead.
  35. func (j *Json) ToStructDeep(pointer interface{}, mapping ...map[string]string) error {
  36. j.mu.RLock()
  37. defer j.mu.RUnlock()
  38. return gconv.StructDeep(*(j.p), pointer, mapping...)
  39. }
  40. // ToStructs converts current Json object to specified object slice.
  41. // The <pointer> should be a pointer type of []struct/*struct.
  42. // Deprecated, use Structs instead.
  43. func (j *Json) ToStructs(pointer interface{}, mapping ...map[string]string) error {
  44. j.mu.RLock()
  45. defer j.mu.RUnlock()
  46. return gconv.Structs(*(j.p), pointer, mapping...)
  47. }
  48. // ToStructsDeep converts current Json object to specified object slice recursively.
  49. // The <pointer> should be a pointer type of []struct/*struct.
  50. // Deprecated, use Structs instead.
  51. func (j *Json) ToStructsDeep(pointer interface{}, mapping ...map[string]string) error {
  52. j.mu.RLock()
  53. defer j.mu.RUnlock()
  54. return gconv.StructsDeep(*(j.p), pointer, mapping...)
  55. }
  56. // ToScan automatically calls Struct or Structs function according to the type of parameter
  57. // <pointer> to implement the converting..
  58. // Deprecated, use Scan instead.
  59. func (j *Json) ToScan(pointer interface{}, mapping ...map[string]string) error {
  60. return gconv.Scan(*(j.p), pointer, mapping...)
  61. }
  62. // ToScanDeep automatically calls StructDeep or StructsDeep function according to the type of
  63. // parameter <pointer> to implement the converting..
  64. // Deprecated, use Scan instead.
  65. func (j *Json) ToScanDeep(pointer interface{}, mapping ...map[string]string) error {
  66. return gconv.ScanDeep(*(j.p), pointer, mapping...)
  67. }
  68. // ToMapToMap converts current Json object to specified map variable.
  69. // The parameter of <pointer> should be type of *map.
  70. // Deprecated, use MapToMap instead.
  71. func (j *Json) ToMapToMap(pointer interface{}, mapping ...map[string]string) error {
  72. j.mu.RLock()
  73. defer j.mu.RUnlock()
  74. return gconv.MapToMap(*(j.p), pointer, mapping...)
  75. }
  76. // ToMapToMapDeep converts current Json object to specified map variable recursively.
  77. // The parameter of <pointer> should be type of *map.
  78. // Deprecated, use MapToMap instead.
  79. func (j *Json) ToMapToMapDeep(pointer interface{}, mapping ...map[string]string) error {
  80. j.mu.RLock()
  81. defer j.mu.RUnlock()
  82. return gconv.MapToMapDeep(*(j.p), pointer, mapping...)
  83. }
  84. // ToMapToMaps converts current Json object to specified map variable slice.
  85. // The parameter of <pointer> should be type of []map/*map.
  86. // Deprecated, use MapToMaps instead.
  87. func (j *Json) ToMapToMaps(pointer interface{}, mapping ...map[string]string) error {
  88. j.mu.RLock()
  89. defer j.mu.RUnlock()
  90. return gconv.MapToMaps(*(j.p), pointer, mapping...)
  91. }
  92. // ToMapToMapsDeep converts current Json object to specified map variable slice recursively.
  93. // The parameter of <pointer> should be type of []map/*map.
  94. // Deprecated, use MapToMaps instead.
  95. func (j *Json) ToMapToMapsDeep(pointer interface{}, mapping ...map[string]string) error {
  96. j.mu.RLock()
  97. defer j.mu.RUnlock()
  98. return gconv.MapToMapsDeep(*(j.p), pointer, mapping...)
  99. }