Я пытаюсь упорядочить JSON в определенном формате, используя Go.Я зацикливаюсь на JSON и печатаю ответ отдельного объекта.Я хочу хранить все объекты в соответствии с форматом.Прямо сейчас я застрял и маршалирую результаты JSON вот так:
{
"Address":null,
"Email":"abc@hotmail.com",
"HashedPassword":"4233137d1c510f2e55ba5cb220b864b11033f156",
"DeHashedPassword":"123456",
"ID":"Gd0YhYEJdE6oejsjBm7xLTQ4lWIaRecbS-k=",
"IPAddress":null,
"Name":null,
"ObtainedFrom":"LinkedIn",
"Password":null,
"Phone":null,
"Username":null,
"Vin":null,
"Success":true
}{
"Address":"",
"Email":"abc@hotmail.com",
"HashedPassword":"",
"DeHashedPassword":"123456",
"ID":"Jge4Mm6M-5-yJedG2ql48M9H2p7qP83aggM=",
"IPAddress":"",
"Name":"",
"ObtainedFrom":"DailyMotion.com",
"Password":"dm_51978c5a67a88",
"Phone":"",
"Username":"",
"Vin":"",
"Success":true
}{
"Address":"",
"Email":"abc@hotmail.com",
"HashedPassword":"",
"DeHashedPassword":"123456",
"ID":"9k8llNeinyrmxhL7yg3zZ50rQiQk_BmzZS8=",
"IPAddress":"",
"Name":"",
"ObtainedFrom":"BreachCompilation",
"Password":"hello123",
"Phone":"",
"Username":"",
"Vin":"",
"Success":true
}
Я хочу получить маршал json вот так
{
"entries": [
{
"id": "CHzLLBdoJiwd7WaySw8QBOoxkj2lmKFhJK8=",
"email": "abc@hotmail.com",
"username": null,
"password": null,
"hashed_password": "4233137d1c510f2e55ba5cb220b864b11033f156",
"name": null,
"vin": null,
"address": null,
"ip_address": null,
"phone": null,
"obtained_from": "LinkedIn"
},
{
"id": "O6W3lxVMo_faf7MWoGGgkMb_CGcjo5vinFQ=",
"email": "abc@hotmail.com",
"username": "",
"password": "dm_51978c5a67a88",
"hashed_password": "",
"name": "",
"vin": "",
"address": "",
"ip_address": "",
"phone": "",
"obtained_from": "DailyMotion.com"
}
],
"success": true
}
Код здесь в Go:
for i := 0; i < len(img.Entries); i++ {
address := img.Entries[i].Address
email1 := img.Entries[i].Email
hashedPassword := img.Entries[i].HashedPassword
deHashedPassword := "12233"
id := img.Entries[i].ID
iPAddress := img.Entries[i].IPAddress
name := img.Entries[i].Name
obtainedFrom := img.Entries[i].ObtainedFrom
password := img.Entries[i].Password
phone := img.Entries[i].Phone
username := img.Entries[i].Username
vin := img.Entries[i].Vin
success := img.Success
group := ColorGroup{
Address: address,
Email: email1,
HashedPassword: hashedPassword,
DeHashedPassword: deHashedPassword,
ID: id,
IPAddress: iPAddress,
Name: name,
ObtainedFrom: obtainedFrom,
Password: password,
Phone: phone,
Username: username,
Vin: vin,
Success: success,
}
b, err := json.Marshal(group)
if err != nil {
fmt.Println("error:", err)
}
ab := string(b)
fmt.Println("New json", ab)
}