go-simplejson icon indicating copy to clipboard operation
go-simplejson copied to clipboard

no way to change jsonObj.MustArray()[i] to *simplejson.Json

Open zhong-wx opened this issue 3 years ago • 2 comments

I want to iterate an array, and use the elements of the array as *simplejson.Json. I found no function to get size of array, the only way I found is to calculate len(jsonObj.Array), and I have no way to change jsonObj.MustArray()[i] to *simplejson.Json.

zhong-wx avatar Feb 18 '21 02:02 zhong-wx

Can you not do this?

arr := jsonObj.MustArray()
for i := 0; i < len(arr); i++ {
        j := &simplejson.Json{data: arr[i]}
       // use j which is *simplejson.Json
}

phanirithvij avatar Jul 25 '21 10:07 phanirithvij

Can you not do this?

arr := jsonObj.MustArray()
for i := 0; i < len(arr); i++ {
        j := &simplejson.Json{data: arr[i]}
       // use j which is *simplejson.Json
}

The 'data' is private so can not unfortunately. We true need a method like JSONArray() []*simplejson.Json

ziposcar avatar Aug 17 '22 12:08 ziposcar