mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 04:57:17 +00:00
Added JavaScript JSON helper
This commit is contained in:
parent
65a802c678
commit
b65f29f8fa
@ -1,6 +1,9 @@
|
||||
package ethutil
|
||||
|
||||
import "reflect"
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// The list type is an anonymous slice handler which can be used
|
||||
// for containing any slice type to use in an environment which
|
||||
@ -44,3 +47,15 @@ func (self *List) Append(v interface{}) {
|
||||
func (self *List) Interface() interface{} {
|
||||
return self.list.Interface()
|
||||
}
|
||||
|
||||
// For JavaScript <3
|
||||
func (self *List) ToJSON() string {
|
||||
var list []interface{}
|
||||
for i := 0; i < self.Length; i++ {
|
||||
list = append(list, self.Get(i))
|
||||
}
|
||||
|
||||
data, _ := json.Marshal(list)
|
||||
|
||||
return string(data)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user