Skip to content
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

json: cannot unmarshal string into Go value of type int64 #92

Closed
andrewarrow opened this issue Aug 1, 2016 · 18 comments
Closed

json: cannot unmarshal string into Go value of type int64 #92

andrewarrow opened this issue Aug 1, 2016 · 18 comments

Comments

@andrewarrow
Copy link

more info coming soon, but get that after calling GetGroupHistory for 1 specific group and then looping thru:

for _, message := range history.Messages
@kodieGlosser
Copy link

kodieGlosser commented Aug 8, 2016

@andrewarrow I was seeing a similar error with one of our slack servers.

I found the bit it was unable to unmarshal.
https://github.com/nlopes/slack/blob/master/attachments.go#L75

Looking at the call to our slack server
https://slack.com/api/rtm.start
token=xxxxxxxxxxxxxx

The json output for the this is datatype string and NOT int64.

I have also noticed with another one of our slack servers, where we do not have this problem, that it does not return "Attachments".

I can see now this is being discussed in issue #90

@andrewarrow
Copy link
Author

@kodieGlosser i'm not seeing this error any more, but I think I muted the group in question causing my problem. In my project I cache each room to disk, so running touch cache/roomname/mute the very presency of that mute file is the binary on/off value for muting. That's not really revelent to this discussion but I think it's cool. I love muting channels by just touching a file from the command line.

@stevenpoitras
Copy link

stevenpoitras commented Aug 23, 2016

Seems like I'm hitting this as well, works fine for some messages but not all. Changing the type to string worked for my scripts

@aspic
Copy link
Contributor

aspic commented Aug 30, 2016

I'm having this problem as well. It was indeed introduced in https://github.com/nlopes/slack/pull/81 and the Slack API specifies TS as an Integer, however the json presents the value as a String.

I've created a fix for this issue in https://github.com/nlopes/slack/pull/96

@kulak-at
Copy link

kulak-at commented Sep 2, 2016

I have the same issue as well, just for some of messages, not for all of them.

@postromantic
Copy link
Contributor

#96 is not a fix for it. Ts should have string type, not int64. In my case "ts":"1473362325.000027" - it doesn't look like int :-)

@andrewarrow
Copy link
Author

u don't want string you want float64

@andrewarrow
Copy link
Author

andrewarrow commented Sep 8, 2016

then int64(ts) to go from 1473362325.000027, to 1473362325

@tobert
Copy link
Contributor

tobert commented Sep 8, 2016

IIRC Slack's docs say it's a string and should not be stored as a float. I can't find the link at the moment. The timestamp is also a message ID and a change in precision would render it incorrect. This is why they send it as a string.

@andrewarrow
Copy link
Author

andrewarrow commented Sep 8, 2016

alright let's store it as a string but have two functions to get either part of the number. The string before the dot and the string after. And then might as well have two more functions for getting both those fields as ints or as parsed Time thingys not really objects cuz golang doesn't have objects.

@aspic
Copy link
Contributor

aspic commented Sep 8, 2016

Ah, I didn't know that the ts could be that precise. Yeah, sounds like the field should be treated as a string in the model.

@postromantic
Copy link
Contributor

Slack discussion about ts field: slackhq/slack-api-docs#7 (comment)

@tonka3000
Copy link

Hey,

i'm also having this problem. Tried a8ceb9d (latest commit at the time) which seems to address these issue but i'm also getting this error

reconnection 4 failed: post: json: invalid use of ,string struct tag, trying to unmarshal unquoted value into int64

@adyatlov
Copy link

adyatlov commented Sep 17, 2016

Hi everyone,

Unfortunately, Slack still can send a number instead of a string in the message.attachments.ts field. So after fetching #99, I'm getting json: cannot unmarshal number into Go value of type string instead of the initial json: cannot unmarshal string into Go value of type int64 #92.

@saxsir
Copy link
Contributor

saxsir commented Sep 19, 2016

I'm having same problem. (getting json: cannot unmarshal number into Go value of type string)

How is use json.Number instead of string ?
https://golang.org/pkg/encoding/json/#Number

Type json.Number is an alias for string.

http://stackoverflow.com/questions/24480835/go-decoding-json-int-into-string

@postromantic
Copy link
Contributor

@saxsir yep, looks like json.Number will cover both cases:
https://play.golang.org/p/75NwTQT-MG

@jpbruinsslot
Copy link

@saxsir his solution fixes it for me too

@saxsir
Copy link
Contributor

saxsir commented Dec 20, 2017

plz close this issue, thx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests