I am trying to represent a slice data as json format so that I can use this vs-code-extension .
But I am getting error in the last line of the for loop.
Error: append(formatted.Rows, col_i) (value of type []RowStructure) is not usedcompilerUnusedExpr
Please help me find out what am I doing wrong and what should be the correct way of assigning slice of structs.
Thankyou
type ColumnStructure struct{
Content string
Tag string
}
type RowStructure struct{
Column ColumnStructure
}
type format struct{
Kind map[string]bool
Text string
Rows []RowStructure
}
func serialize(s []int){
var formatted format
for i := 0; i < len(s); i++ {
var col_i = ColumnStructure{
Content: string(s[i]),
Tag: string(s[i]),
}
append(formatted.Rows,col_i)
}
}
func main() {
var s = []int{1, 12, 30, 4, 5}
formatted_data := serialize(s)
fmt.Println(formatted_data)
}
After doing certain changes to the code, following code works fine now. But I am still not able to get the visualizations from this vs-code-extension.
type ColumnStructure struct {
Content string
Tag string
}
type RowStructure struct {
Column ColumnStructure
}
type format struct {
Kind map[string]bool
Text string
Rows []RowStructure
}
func serialize(s []int) format {
var formatted format
for i := 0; i < len(s); i++ {
var col_i = ColumnStructure{
Content: string(s[i]),
Tag: string(s[i]),
}
var row = RowStructure{
Column: col_i,
}
formatted.Rows = append(formatted.Rows, row)
}
return formatted
}
func main() {
var s = []int{1, 12, 30, 4, 5}
formatted_data := serialize(s)
fmt.Println(formatted_data)
for i := 0; i < len(s)-1; i++ {
if s[i] < s[i+1] {
s[i], s[i+1] = s[i+1], s[i]
}
}
fmt.Println(s)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.