Is it possible to bind to map object of custom struct type?












0















my question is,
how to bind(auto binding?) custom structure type in a map object(variable)?



this is my custom struct type



type Tetris struct {
... ...
NowBlock map[string]int `form:"nowBlock" json:"nowBlock"`
... ...
}


this is my ajax code



 $.ajax({
type : "POST"
, url : "/game/tetris/api/control"
, data : {
"keyCode" : keyCode
, "ctxWidth" : ctxWidth
, "ctxHeight" : ctxHeight
, "nowBlock" : {"O":0}
} // also, i did JSON.stringify, but did not binding..
, dataType : "json"
, contentType : "application/json"
}).done(function(data){
... ...
});


and then, do not binding 'NowBlock'



tetris := new(Tetris)
if err := c.Bind(tetris); err != nil {
c.Logger().Error(err)
}
fmt.Println(tetris.NowBlock)


the println result is ,



'map' //nil...


this is my full question link(GOLANG > How to bind ajax json data to custom struct type?)



please help me.






ps. thank you for answer me.
I did like the answer.
BUT, it does not working too.



First,



- No 'contentType : "application/json"'
- don't use JSON.stringify

then, in go side,
- fmt.println(tetris.KeyCode) // OK
- fmt.println(tetris.NowBlock) // NOT OK.. 'map'


Second,



- Use 'contentType : "application/json"'
- Use JSON.stringify

then, in go side,
- fmt.println(tetris.KeyCode) // NOT OK.. '' (nil)
- fmt.println(tetris.NowBlock) // NOT OK.. 'map'


Third,



i remove the custom struct type Tetris NowBlock object's `form:nowBlock` literal, 
but is does not working too...


why not binding Custom structure type in a map object?







i'm so so sorry. i solve this question.
the problem that is my go custom struct type have another custom struct type.



like this.



type Tetris struct {
Common Common

NowBlock map[string]int `json:"nowBlock"`
}

type Common struct {
CtxWidth int `json:"ctxWidth"`
CtxHeight int `json:"ctxHeight"`

KeyCode int `form:"keyCode" json:"keyCode"`
}


in this case, i did



 $.ajax({
type : "POST"
, url : "/game/tetris/api/control"
, data : {
"keyCode" : keyCode
, "ctxWidth" : ctxWidth
, "ctxHeight" : ctxHeight
, "nowBlock" : {"O":0}
} // also, i did JSON.stringify, but did not binding..
, dataType : "json"
, contentType : "application/json"
}).done(function(data){
... ...


});



but, this is wrong!
the correct is,



$.ajax({
type : "POST"
, url : "/game/tetris/api/control"
, data : JSON.stringify({
"Common" : {
"keyCode" : keyCode
, "ctxWidth" : ctxWidth
, "ctxHeight" : ctxHeight
}
, "nowBlock" : {"O":0}
})
, dataType : "json"
, contentType : "application/json"
}).done(function(data){
... ...


in json data, 'Common' struct type's data must have "Common" 'Key:value' map...



i'm very glade to your answers and attentions.










share|improve this question

























  • May we know what c is?

    – ssemilla
    Nov 21 '18 at 5:04











  • i'm sorry. That 'c' is context.( echo framework link > echo.labstack.com/guide/request)

    – gdk
    Nov 21 '18 at 5:26
















0















my question is,
how to bind(auto binding?) custom structure type in a map object(variable)?



this is my custom struct type



type Tetris struct {
... ...
NowBlock map[string]int `form:"nowBlock" json:"nowBlock"`
... ...
}


this is my ajax code



 $.ajax({
type : "POST"
, url : "/game/tetris/api/control"
, data : {
"keyCode" : keyCode
, "ctxWidth" : ctxWidth
, "ctxHeight" : ctxHeight
, "nowBlock" : {"O":0}
} // also, i did JSON.stringify, but did not binding..
, dataType : "json"
, contentType : "application/json"
}).done(function(data){
... ...
});


and then, do not binding 'NowBlock'



tetris := new(Tetris)
if err := c.Bind(tetris); err != nil {
c.Logger().Error(err)
}
fmt.Println(tetris.NowBlock)


the println result is ,



'map' //nil...


this is my full question link(GOLANG > How to bind ajax json data to custom struct type?)



please help me.






ps. thank you for answer me.
I did like the answer.
BUT, it does not working too.



First,



- No 'contentType : "application/json"'
- don't use JSON.stringify

then, in go side,
- fmt.println(tetris.KeyCode) // OK
- fmt.println(tetris.NowBlock) // NOT OK.. 'map'


Second,



- Use 'contentType : "application/json"'
- Use JSON.stringify

then, in go side,
- fmt.println(tetris.KeyCode) // NOT OK.. '' (nil)
- fmt.println(tetris.NowBlock) // NOT OK.. 'map'


Third,



i remove the custom struct type Tetris NowBlock object's `form:nowBlock` literal, 
but is does not working too...


why not binding Custom structure type in a map object?







i'm so so sorry. i solve this question.
the problem that is my go custom struct type have another custom struct type.



like this.



type Tetris struct {
Common Common

NowBlock map[string]int `json:"nowBlock"`
}

type Common struct {
CtxWidth int `json:"ctxWidth"`
CtxHeight int `json:"ctxHeight"`

KeyCode int `form:"keyCode" json:"keyCode"`
}


in this case, i did



 $.ajax({
type : "POST"
, url : "/game/tetris/api/control"
, data : {
"keyCode" : keyCode
, "ctxWidth" : ctxWidth
, "ctxHeight" : ctxHeight
, "nowBlock" : {"O":0}
} // also, i did JSON.stringify, but did not binding..
, dataType : "json"
, contentType : "application/json"
}).done(function(data){
... ...


});



but, this is wrong!
the correct is,



$.ajax({
type : "POST"
, url : "/game/tetris/api/control"
, data : JSON.stringify({
"Common" : {
"keyCode" : keyCode
, "ctxWidth" : ctxWidth
, "ctxHeight" : ctxHeight
}
, "nowBlock" : {"O":0}
})
, dataType : "json"
, contentType : "application/json"
}).done(function(data){
... ...


in json data, 'Common' struct type's data must have "Common" 'Key:value' map...



i'm very glade to your answers and attentions.










share|improve this question

























  • May we know what c is?

    – ssemilla
    Nov 21 '18 at 5:04











  • i'm sorry. That 'c' is context.( echo framework link > echo.labstack.com/guide/request)

    – gdk
    Nov 21 '18 at 5:26














0












0








0








my question is,
how to bind(auto binding?) custom structure type in a map object(variable)?



this is my custom struct type



type Tetris struct {
... ...
NowBlock map[string]int `form:"nowBlock" json:"nowBlock"`
... ...
}


this is my ajax code



 $.ajax({
type : "POST"
, url : "/game/tetris/api/control"
, data : {
"keyCode" : keyCode
, "ctxWidth" : ctxWidth
, "ctxHeight" : ctxHeight
, "nowBlock" : {"O":0}
} // also, i did JSON.stringify, but did not binding..
, dataType : "json"
, contentType : "application/json"
}).done(function(data){
... ...
});


and then, do not binding 'NowBlock'



tetris := new(Tetris)
if err := c.Bind(tetris); err != nil {
c.Logger().Error(err)
}
fmt.Println(tetris.NowBlock)


the println result is ,



'map' //nil...


this is my full question link(GOLANG > How to bind ajax json data to custom struct type?)



please help me.






ps. thank you for answer me.
I did like the answer.
BUT, it does not working too.



First,



- No 'contentType : "application/json"'
- don't use JSON.stringify

then, in go side,
- fmt.println(tetris.KeyCode) // OK
- fmt.println(tetris.NowBlock) // NOT OK.. 'map'


Second,



- Use 'contentType : "application/json"'
- Use JSON.stringify

then, in go side,
- fmt.println(tetris.KeyCode) // NOT OK.. '' (nil)
- fmt.println(tetris.NowBlock) // NOT OK.. 'map'


Third,



i remove the custom struct type Tetris NowBlock object's `form:nowBlock` literal, 
but is does not working too...


why not binding Custom structure type in a map object?







i'm so so sorry. i solve this question.
the problem that is my go custom struct type have another custom struct type.



like this.



type Tetris struct {
Common Common

NowBlock map[string]int `json:"nowBlock"`
}

type Common struct {
CtxWidth int `json:"ctxWidth"`
CtxHeight int `json:"ctxHeight"`

KeyCode int `form:"keyCode" json:"keyCode"`
}


in this case, i did



 $.ajax({
type : "POST"
, url : "/game/tetris/api/control"
, data : {
"keyCode" : keyCode
, "ctxWidth" : ctxWidth
, "ctxHeight" : ctxHeight
, "nowBlock" : {"O":0}
} // also, i did JSON.stringify, but did not binding..
, dataType : "json"
, contentType : "application/json"
}).done(function(data){
... ...


});



but, this is wrong!
the correct is,



$.ajax({
type : "POST"
, url : "/game/tetris/api/control"
, data : JSON.stringify({
"Common" : {
"keyCode" : keyCode
, "ctxWidth" : ctxWidth
, "ctxHeight" : ctxHeight
}
, "nowBlock" : {"O":0}
})
, dataType : "json"
, contentType : "application/json"
}).done(function(data){
... ...


in json data, 'Common' struct type's data must have "Common" 'Key:value' map...



i'm very glade to your answers and attentions.










share|improve this question
















my question is,
how to bind(auto binding?) custom structure type in a map object(variable)?



this is my custom struct type



type Tetris struct {
... ...
NowBlock map[string]int `form:"nowBlock" json:"nowBlock"`
... ...
}


this is my ajax code



 $.ajax({
type : "POST"
, url : "/game/tetris/api/control"
, data : {
"keyCode" : keyCode
, "ctxWidth" : ctxWidth
, "ctxHeight" : ctxHeight
, "nowBlock" : {"O":0}
} // also, i did JSON.stringify, but did not binding..
, dataType : "json"
, contentType : "application/json"
}).done(function(data){
... ...
});


and then, do not binding 'NowBlock'



tetris := new(Tetris)
if err := c.Bind(tetris); err != nil {
c.Logger().Error(err)
}
fmt.Println(tetris.NowBlock)


the println result is ,



'map' //nil...


this is my full question link(GOLANG > How to bind ajax json data to custom struct type?)



please help me.






ps. thank you for answer me.
I did like the answer.
BUT, it does not working too.



First,



- No 'contentType : "application/json"'
- don't use JSON.stringify

then, in go side,
- fmt.println(tetris.KeyCode) // OK
- fmt.println(tetris.NowBlock) // NOT OK.. 'map'


Second,



- Use 'contentType : "application/json"'
- Use JSON.stringify

then, in go side,
- fmt.println(tetris.KeyCode) // NOT OK.. '' (nil)
- fmt.println(tetris.NowBlock) // NOT OK.. 'map'


Third,



i remove the custom struct type Tetris NowBlock object's `form:nowBlock` literal, 
but is does not working too...


why not binding Custom structure type in a map object?







i'm so so sorry. i solve this question.
the problem that is my go custom struct type have another custom struct type.



like this.



type Tetris struct {
Common Common

NowBlock map[string]int `json:"nowBlock"`
}

type Common struct {
CtxWidth int `json:"ctxWidth"`
CtxHeight int `json:"ctxHeight"`

KeyCode int `form:"keyCode" json:"keyCode"`
}


in this case, i did



 $.ajax({
type : "POST"
, url : "/game/tetris/api/control"
, data : {
"keyCode" : keyCode
, "ctxWidth" : ctxWidth
, "ctxHeight" : ctxHeight
, "nowBlock" : {"O":0}
} // also, i did JSON.stringify, but did not binding..
, dataType : "json"
, contentType : "application/json"
}).done(function(data){
... ...


});



but, this is wrong!
the correct is,



$.ajax({
type : "POST"
, url : "/game/tetris/api/control"
, data : JSON.stringify({
"Common" : {
"keyCode" : keyCode
, "ctxWidth" : ctxWidth
, "ctxHeight" : ctxHeight
}
, "nowBlock" : {"O":0}
})
, dataType : "json"
, contentType : "application/json"
}).done(function(data){
... ...


in json data, 'Common' struct type's data must have "Common" 'Key:value' map...



i'm very glade to your answers and attentions.







json go data-binding echo-framework






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 8:47







gdk

















asked Nov 21 '18 at 4:41









gdkgdk

65




65













  • May we know what c is?

    – ssemilla
    Nov 21 '18 at 5:04











  • i'm sorry. That 'c' is context.( echo framework link > echo.labstack.com/guide/request)

    – gdk
    Nov 21 '18 at 5:26



















  • May we know what c is?

    – ssemilla
    Nov 21 '18 at 5:04











  • i'm sorry. That 'c' is context.( echo framework link > echo.labstack.com/guide/request)

    – gdk
    Nov 21 '18 at 5:26

















May we know what c is?

– ssemilla
Nov 21 '18 at 5:04





May we know what c is?

– ssemilla
Nov 21 '18 at 5:04













i'm sorry. That 'c' is context.( echo framework link > echo.labstack.com/guide/request)

– gdk
Nov 21 '18 at 5:26





i'm sorry. That 'c' is context.( echo framework link > echo.labstack.com/guide/request)

– gdk
Nov 21 '18 at 5:26












2 Answers
2






active

oldest

votes


















0














There is no problem in your go code. Why echo .Bind() not able to retrieve the payload sent from AJAX is because the payload is not in JSON format.



On $.ajax you need to JSON.stringify() the data into JSON string format.



JSON.stringify({
"keyCode" : keyCode
, "ctxWidth" : ctxWidth
, "ctxHeight" : ctxHeight
, "nowBlock" : {"O":0}
})


Setting contentType into application/json will not automatically convert payload into JSON string. That's why JSON.stringy() is still required.





Full changes:



var payload = JSON.stringify({
"keyCode": keyCode,
"ctxWidth": ctxWidth,
"ctxHeight": ctxHeight,
"nowBlock": {
"O": 0
}
})

$.ajax({
type: "POST",
url: "/game/tetris/api/control",
data: payload,
dataType: "json",
contentType: "application/json"
}).done(function(data) {
......
});





share|improve this answer
























  • thank you. first, i was remove contentType in ajax, GO tetris.KeyCode > working // printing 'key code: 13..' but, tetris.NowBlock > don't working.. // pringing 'map' second, contentType: "application/json" and data: stringify({json..}) GO tetris.KeyCode > don't working // printing nil but, tetris.NowBlock > don't working.. // pringing 'map'

    – gdk
    Nov 21 '18 at 6:48













  • if you remove the contentType, the payload will sent with content type application/x-www-form-urlencoded. some array information will be unreadable

    – xpare
    Nov 21 '18 at 6:50











  • sorry my comment was incorrect. so i edit my question(please read the end of question).

    – gdk
    Nov 21 '18 at 7:01



















0














Maybe you should remove struct tag 'form', when you use 'application/json' send data, 'form' tag is unused.

The program is going well when I just add 'json' tag, and if I add 'form' tag, echo uses the 'form' and get an error.



Hope this can help you.






share|improve this answer
























  • thank you. i did remove 'form' literal, but it did not working...

    – gdk
    Nov 21 '18 at 6:46











  • @gdk if you send js data with content-type=application/json ?, you can check is with this way. 1. if data send correct, ioutil.ReadAll(c.Request().Body), this should be the json data you had sent. 2. you have the correct struct to bind to the json data. 3. use the correct struct tag. Echo bind data by struct tag and content-type, tag json for application/json, tag form for application/x-www-form-urlencoded, tag query for parameters in url. There is my test code: goplay.space/#A70IHubaQIH

    – Laily
    Nov 22 '18 at 7:46













  • Tank you so much. i changed my ajax code. added code is 'application/json'. And end of my question, my mistake was custom struct type's object other custom struct type. That’s very kind of you!

    – gdk
    Nov 22 '18 at 8:51











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405374%2fis-it-possible-to-bind-to-map-object-of-custom-struct-type%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














There is no problem in your go code. Why echo .Bind() not able to retrieve the payload sent from AJAX is because the payload is not in JSON format.



On $.ajax you need to JSON.stringify() the data into JSON string format.



JSON.stringify({
"keyCode" : keyCode
, "ctxWidth" : ctxWidth
, "ctxHeight" : ctxHeight
, "nowBlock" : {"O":0}
})


Setting contentType into application/json will not automatically convert payload into JSON string. That's why JSON.stringy() is still required.





Full changes:



var payload = JSON.stringify({
"keyCode": keyCode,
"ctxWidth": ctxWidth,
"ctxHeight": ctxHeight,
"nowBlock": {
"O": 0
}
})

$.ajax({
type: "POST",
url: "/game/tetris/api/control",
data: payload,
dataType: "json",
contentType: "application/json"
}).done(function(data) {
......
});





share|improve this answer
























  • thank you. first, i was remove contentType in ajax, GO tetris.KeyCode > working // printing 'key code: 13..' but, tetris.NowBlock > don't working.. // pringing 'map' second, contentType: "application/json" and data: stringify({json..}) GO tetris.KeyCode > don't working // printing nil but, tetris.NowBlock > don't working.. // pringing 'map'

    – gdk
    Nov 21 '18 at 6:48













  • if you remove the contentType, the payload will sent with content type application/x-www-form-urlencoded. some array information will be unreadable

    – xpare
    Nov 21 '18 at 6:50











  • sorry my comment was incorrect. so i edit my question(please read the end of question).

    – gdk
    Nov 21 '18 at 7:01
















0














There is no problem in your go code. Why echo .Bind() not able to retrieve the payload sent from AJAX is because the payload is not in JSON format.



On $.ajax you need to JSON.stringify() the data into JSON string format.



JSON.stringify({
"keyCode" : keyCode
, "ctxWidth" : ctxWidth
, "ctxHeight" : ctxHeight
, "nowBlock" : {"O":0}
})


Setting contentType into application/json will not automatically convert payload into JSON string. That's why JSON.stringy() is still required.





Full changes:



var payload = JSON.stringify({
"keyCode": keyCode,
"ctxWidth": ctxWidth,
"ctxHeight": ctxHeight,
"nowBlock": {
"O": 0
}
})

$.ajax({
type: "POST",
url: "/game/tetris/api/control",
data: payload,
dataType: "json",
contentType: "application/json"
}).done(function(data) {
......
});





share|improve this answer
























  • thank you. first, i was remove contentType in ajax, GO tetris.KeyCode > working // printing 'key code: 13..' but, tetris.NowBlock > don't working.. // pringing 'map' second, contentType: "application/json" and data: stringify({json..}) GO tetris.KeyCode > don't working // printing nil but, tetris.NowBlock > don't working.. // pringing 'map'

    – gdk
    Nov 21 '18 at 6:48













  • if you remove the contentType, the payload will sent with content type application/x-www-form-urlencoded. some array information will be unreadable

    – xpare
    Nov 21 '18 at 6:50











  • sorry my comment was incorrect. so i edit my question(please read the end of question).

    – gdk
    Nov 21 '18 at 7:01














0












0








0







There is no problem in your go code. Why echo .Bind() not able to retrieve the payload sent from AJAX is because the payload is not in JSON format.



On $.ajax you need to JSON.stringify() the data into JSON string format.



JSON.stringify({
"keyCode" : keyCode
, "ctxWidth" : ctxWidth
, "ctxHeight" : ctxHeight
, "nowBlock" : {"O":0}
})


Setting contentType into application/json will not automatically convert payload into JSON string. That's why JSON.stringy() is still required.





Full changes:



var payload = JSON.stringify({
"keyCode": keyCode,
"ctxWidth": ctxWidth,
"ctxHeight": ctxHeight,
"nowBlock": {
"O": 0
}
})

$.ajax({
type: "POST",
url: "/game/tetris/api/control",
data: payload,
dataType: "json",
contentType: "application/json"
}).done(function(data) {
......
});





share|improve this answer













There is no problem in your go code. Why echo .Bind() not able to retrieve the payload sent from AJAX is because the payload is not in JSON format.



On $.ajax you need to JSON.stringify() the data into JSON string format.



JSON.stringify({
"keyCode" : keyCode
, "ctxWidth" : ctxWidth
, "ctxHeight" : ctxHeight
, "nowBlock" : {"O":0}
})


Setting contentType into application/json will not automatically convert payload into JSON string. That's why JSON.stringy() is still required.





Full changes:



var payload = JSON.stringify({
"keyCode": keyCode,
"ctxWidth": ctxWidth,
"ctxHeight": ctxHeight,
"nowBlock": {
"O": 0
}
})

$.ajax({
type: "POST",
url: "/game/tetris/api/control",
data: payload,
dataType: "json",
contentType: "application/json"
}).done(function(data) {
......
});






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 6:14









xparexpare

4,6972248




4,6972248













  • thank you. first, i was remove contentType in ajax, GO tetris.KeyCode > working // printing 'key code: 13..' but, tetris.NowBlock > don't working.. // pringing 'map' second, contentType: "application/json" and data: stringify({json..}) GO tetris.KeyCode > don't working // printing nil but, tetris.NowBlock > don't working.. // pringing 'map'

    – gdk
    Nov 21 '18 at 6:48













  • if you remove the contentType, the payload will sent with content type application/x-www-form-urlencoded. some array information will be unreadable

    – xpare
    Nov 21 '18 at 6:50











  • sorry my comment was incorrect. so i edit my question(please read the end of question).

    – gdk
    Nov 21 '18 at 7:01



















  • thank you. first, i was remove contentType in ajax, GO tetris.KeyCode > working // printing 'key code: 13..' but, tetris.NowBlock > don't working.. // pringing 'map' second, contentType: "application/json" and data: stringify({json..}) GO tetris.KeyCode > don't working // printing nil but, tetris.NowBlock > don't working.. // pringing 'map'

    – gdk
    Nov 21 '18 at 6:48













  • if you remove the contentType, the payload will sent with content type application/x-www-form-urlencoded. some array information will be unreadable

    – xpare
    Nov 21 '18 at 6:50











  • sorry my comment was incorrect. so i edit my question(please read the end of question).

    – gdk
    Nov 21 '18 at 7:01

















thank you. first, i was remove contentType in ajax, GO tetris.KeyCode > working // printing 'key code: 13..' but, tetris.NowBlock > don't working.. // pringing 'map' second, contentType: "application/json" and data: stringify({json..}) GO tetris.KeyCode > don't working // printing nil but, tetris.NowBlock > don't working.. // pringing 'map'

– gdk
Nov 21 '18 at 6:48







thank you. first, i was remove contentType in ajax, GO tetris.KeyCode > working // printing 'key code: 13..' but, tetris.NowBlock > don't working.. // pringing 'map' second, contentType: "application/json" and data: stringify({json..}) GO tetris.KeyCode > don't working // printing nil but, tetris.NowBlock > don't working.. // pringing 'map'

– gdk
Nov 21 '18 at 6:48















if you remove the contentType, the payload will sent with content type application/x-www-form-urlencoded. some array information will be unreadable

– xpare
Nov 21 '18 at 6:50





if you remove the contentType, the payload will sent with content type application/x-www-form-urlencoded. some array information will be unreadable

– xpare
Nov 21 '18 at 6:50













sorry my comment was incorrect. so i edit my question(please read the end of question).

– gdk
Nov 21 '18 at 7:01





sorry my comment was incorrect. so i edit my question(please read the end of question).

– gdk
Nov 21 '18 at 7:01













0














Maybe you should remove struct tag 'form', when you use 'application/json' send data, 'form' tag is unused.

The program is going well when I just add 'json' tag, and if I add 'form' tag, echo uses the 'form' and get an error.



Hope this can help you.






share|improve this answer
























  • thank you. i did remove 'form' literal, but it did not working...

    – gdk
    Nov 21 '18 at 6:46











  • @gdk if you send js data with content-type=application/json ?, you can check is with this way. 1. if data send correct, ioutil.ReadAll(c.Request().Body), this should be the json data you had sent. 2. you have the correct struct to bind to the json data. 3. use the correct struct tag. Echo bind data by struct tag and content-type, tag json for application/json, tag form for application/x-www-form-urlencoded, tag query for parameters in url. There is my test code: goplay.space/#A70IHubaQIH

    – Laily
    Nov 22 '18 at 7:46













  • Tank you so much. i changed my ajax code. added code is 'application/json'. And end of my question, my mistake was custom struct type's object other custom struct type. That’s very kind of you!

    – gdk
    Nov 22 '18 at 8:51
















0














Maybe you should remove struct tag 'form', when you use 'application/json' send data, 'form' tag is unused.

The program is going well when I just add 'json' tag, and if I add 'form' tag, echo uses the 'form' and get an error.



Hope this can help you.






share|improve this answer
























  • thank you. i did remove 'form' literal, but it did not working...

    – gdk
    Nov 21 '18 at 6:46











  • @gdk if you send js data with content-type=application/json ?, you can check is with this way. 1. if data send correct, ioutil.ReadAll(c.Request().Body), this should be the json data you had sent. 2. you have the correct struct to bind to the json data. 3. use the correct struct tag. Echo bind data by struct tag and content-type, tag json for application/json, tag form for application/x-www-form-urlencoded, tag query for parameters in url. There is my test code: goplay.space/#A70IHubaQIH

    – Laily
    Nov 22 '18 at 7:46













  • Tank you so much. i changed my ajax code. added code is 'application/json'. And end of my question, my mistake was custom struct type's object other custom struct type. That’s very kind of you!

    – gdk
    Nov 22 '18 at 8:51














0












0








0







Maybe you should remove struct tag 'form', when you use 'application/json' send data, 'form' tag is unused.

The program is going well when I just add 'json' tag, and if I add 'form' tag, echo uses the 'form' and get an error.



Hope this can help you.






share|improve this answer













Maybe you should remove struct tag 'form', when you use 'application/json' send data, 'form' tag is unused.

The program is going well when I just add 'json' tag, and if I add 'form' tag, echo uses the 'form' and get an error.



Hope this can help you.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 6:11









LailyLaily

1,8961910




1,8961910













  • thank you. i did remove 'form' literal, but it did not working...

    – gdk
    Nov 21 '18 at 6:46











  • @gdk if you send js data with content-type=application/json ?, you can check is with this way. 1. if data send correct, ioutil.ReadAll(c.Request().Body), this should be the json data you had sent. 2. you have the correct struct to bind to the json data. 3. use the correct struct tag. Echo bind data by struct tag and content-type, tag json for application/json, tag form for application/x-www-form-urlencoded, tag query for parameters in url. There is my test code: goplay.space/#A70IHubaQIH

    – Laily
    Nov 22 '18 at 7:46













  • Tank you so much. i changed my ajax code. added code is 'application/json'. And end of my question, my mistake was custom struct type's object other custom struct type. That’s very kind of you!

    – gdk
    Nov 22 '18 at 8:51



















  • thank you. i did remove 'form' literal, but it did not working...

    – gdk
    Nov 21 '18 at 6:46











  • @gdk if you send js data with content-type=application/json ?, you can check is with this way. 1. if data send correct, ioutil.ReadAll(c.Request().Body), this should be the json data you had sent. 2. you have the correct struct to bind to the json data. 3. use the correct struct tag. Echo bind data by struct tag and content-type, tag json for application/json, tag form for application/x-www-form-urlencoded, tag query for parameters in url. There is my test code: goplay.space/#A70IHubaQIH

    – Laily
    Nov 22 '18 at 7:46













  • Tank you so much. i changed my ajax code. added code is 'application/json'. And end of my question, my mistake was custom struct type's object other custom struct type. That’s very kind of you!

    – gdk
    Nov 22 '18 at 8:51

















thank you. i did remove 'form' literal, but it did not working...

– gdk
Nov 21 '18 at 6:46





thank you. i did remove 'form' literal, but it did not working...

– gdk
Nov 21 '18 at 6:46













@gdk if you send js data with content-type=application/json ?, you can check is with this way. 1. if data send correct, ioutil.ReadAll(c.Request().Body), this should be the json data you had sent. 2. you have the correct struct to bind to the json data. 3. use the correct struct tag. Echo bind data by struct tag and content-type, tag json for application/json, tag form for application/x-www-form-urlencoded, tag query for parameters in url. There is my test code: goplay.space/#A70IHubaQIH

– Laily
Nov 22 '18 at 7:46







@gdk if you send js data with content-type=application/json ?, you can check is with this way. 1. if data send correct, ioutil.ReadAll(c.Request().Body), this should be the json data you had sent. 2. you have the correct struct to bind to the json data. 3. use the correct struct tag. Echo bind data by struct tag and content-type, tag json for application/json, tag form for application/x-www-form-urlencoded, tag query for parameters in url. There is my test code: goplay.space/#A70IHubaQIH

– Laily
Nov 22 '18 at 7:46















Tank you so much. i changed my ajax code. added code is 'application/json'. And end of my question, my mistake was custom struct type's object other custom struct type. That’s very kind of you!

– gdk
Nov 22 '18 at 8:51





Tank you so much. i changed my ajax code. added code is 'application/json'. And end of my question, my mistake was custom struct type's object other custom struct type. That’s very kind of you!

– gdk
Nov 22 '18 at 8:51


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405374%2fis-it-possible-to-bind-to-map-object-of-custom-struct-type%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]