github.com/free5gc/openapi@v1.0.8/json_query_builder.go (about)

     1  package openapi
     2  
     3  import (
     4  	"encoding/json"
     5  	"reflect"
     6  )
     7  
     8  func MarshToJsonString(v interface{}) (result []string) {
     9  	types := reflect.TypeOf(v)
    10  	val := reflect.ValueOf(v)
    11  	if types.Kind() == reflect.Slice {
    12  		for i := 0; i < val.Len(); i++ {
    13  			tmp, _ := json.Marshal(val.Index(i).Interface())
    14  			result = append(result, string(tmp))
    15  		}
    16  	} else {
    17  		tmp, _ := json.Marshal(v)
    18  		result = append(result, string(tmp))
    19  	}
    20  	return
    21  }