Skip to content

Commit

Permalink
Removed StringArray()
Browse files Browse the repository at this point in the history
Too specific, should use Array() or JsonArray() instead, and then cast the individual values as the type that you need.
  • Loading branch information
AzuraMeta committed Jul 17, 2014
1 parent bb58a70 commit cfb04ab
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 33 deletions.
21 changes: 0 additions & 21 deletions simplejson.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,27 +241,6 @@ func (j *Json) Bytes() ([]byte, error) {
return nil, errors.New("type assertion to []byte failed")
}

// StringArray type asserts to an `array` of `string`
func (j *Json) StringArray() ([]string, error) {
arr, err := j.Array()
if err != nil {
return nil, err
}
retArr := make([]string, 0, len(arr))
for _, a := range arr {
if a == nil {
retArr = append(retArr, "")
continue
}
s, ok := a.(string)
if !ok {
return nil, err
}
retArr = append(retArr, s)
}
return retArr, nil
}

// MustJsonArray guarantees the return of a `[]interface{}` (with optional default)
func (j *Json) MustJsonArray(args ...[]*Json) []*Json {
var def []*Json
Expand Down
12 changes: 0 additions & 12 deletions simplejson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,6 @@ func TestSimplejson(t *testing.T) {
mm2 := js.Get("test").Get("missing_map").MustMap(map[string]interface{}{"found": false})
assert.Equal(t, mm2, map[string]interface{}{"found": false})

strs, err := js.Get("test").Get("string_array").StringArray()
assert.Equal(t, err, nil)
assert.Equal(t, strs[0], "asdf")
assert.Equal(t, strs[1], "ghjk")
assert.Equal(t, strs[2], "zxcv")

strs2, err := js.Get("test").Get("string_array_null").StringArray()
assert.Equal(t, err, nil)
assert.Equal(t, strs2[0], "abc")
assert.Equal(t, strs2[1], "")
assert.Equal(t, strs2[2], "efg")

gp, _ := js.Get("test", "string").String()
assert.Equal(t, "simplejson", gp)

Expand Down

0 comments on commit cfb04ab

Please sign in to comment.