New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how do we return an array of json as response #87
Comments
Has the expected result:
|
@alexandernyquist is right. |
For context.JSON supporting slice of nested structs
in result ExtraData looks empty even though ExtraData exist
when assigning to an interface slice everything seems to work out.
For now i'm reassigning to interfaceslice. Is there a better way to do this? |
@thellimist byteSlice,err := json.Marshal(yourSlice) Can you see ExtraData in the json output if you do it this way? Do you get You say, "nested arrays", but it looks like ExtraData is just a dictionary, make sure you are using a slice to hold the data that is inside ExtraData (eg. []TagExtra) if you want an array. Lastly, you don't want to display ExtraData if its empty, but you are sacrificing your output fieldname to do so. The "encoding/json" package allows you to double up with the omitempty option like so: On Mon, Aug 24, 2015 at 3:26 PM, Furkan Yilmaz notifications@github.com
|
this doesn't work.
I meant "slice of nested structs" sorry for that misunderstanding. Edited the comment |
@thellimist could you post the code for your getTags() function? I'm trying to figure out where in your Extra struct the non interface type screws with encoding/json. When you said array I knew you meant slice, I just wanted to make sure you were storing a slice []ExtraData and not just ExtraData in your top level struct. |
and getTags returns
So expected result will be something like
but instead it returns
I hope I was able to clarify. Thank you. |
I also want to know how to response that string as json. |
from the example looks like we can only return a single json file for response? could you please advice? thanks
The text was updated successfully, but these errors were encountered: