Answer the question
In order to leave comments, you need to log in
How to put comma in json?
For example, I want to make the structure identical to the VK answer:
[{...},{...},{...},{...}]
Every time I add data, they are not separated by a comma.
JSON, _ := json.Marshal(userVar1)
fmt.Println(string(JSON))
[{...}{...}{...}{...}]
Answer the question
In order to leave comments, you need to log in
package main
import (
"encoding/json"
"fmt"
)
type Responses struct {
ID int `json:"id"`
Name string `json:"name"`}
func main() {
var jsonByte = []byte(`[{"ID": 1, "Name": "Пашка"}]`)
var respos []Responses
json.Unmarshal(jsonByte, &respos)
for j := 0; j <= 20; j++ {
respos = append(respos, Responses{ID: j, Name: "Решил"})
}
result, _ := json.Marshal(respos)
fmt.Println(string(result))
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question