diff options
author | obscuren <geffobscura@gmail.com> | 2014-09-22 20:51:41 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-09-22 20:51:41 +0800 |
commit | b65f29f8faa20a93bd83c18232326c935cb16981 (patch) | |
tree | e4720d492db229b25a3ff41fd6c606862b927111 /ethutil | |
parent | 65a802c6787184951753ba2f79fdf60dce526721 (diff) | |
download | dexon-b65f29f8faa20a93bd83c18232326c935cb16981.tar dexon-b65f29f8faa20a93bd83c18232326c935cb16981.tar.gz dexon-b65f29f8faa20a93bd83c18232326c935cb16981.tar.bz2 dexon-b65f29f8faa20a93bd83c18232326c935cb16981.tar.lz dexon-b65f29f8faa20a93bd83c18232326c935cb16981.tar.xz dexon-b65f29f8faa20a93bd83c18232326c935cb16981.tar.zst dexon-b65f29f8faa20a93bd83c18232326c935cb16981.zip |
Added JavaScript JSON helper
Diffstat (limited to 'ethutil')
-rw-r--r-- | ethutil/list.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/ethutil/list.go b/ethutil/list.go index 0aa657a14..9db96cf18 100644 --- a/ethutil/list.go +++ b/ethutil/list.go @@ -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) +} |