feature_adapter.go 446 B

1234567891011121314151617181920212223242526
  1. package jsoniter
  2. import (
  3. "io"
  4. "unsafe"
  5. )
  6. // Unmarshal adapts to json/encoding APIs
  7. func Unmarshal(data []byte, v interface{}) error {
  8. iter := ParseBytes(data)
  9. iter.Read(v)
  10. if iter.Error == io.EOF {
  11. return nil
  12. }
  13. return iter.Error
  14. }
  15. func UnmarshalString(str string, v interface{}) error {
  16. data := *(*[]byte)(unsafe.Pointer(&str))
  17. iter := ParseBytes(data)
  18. iter.Read(v)
  19. if iter.Error == io.EOF {
  20. return nil
  21. }
  22. return iter.Error
  23. }