V
V
varstring2017-09-03 20:11:31
go
varstring, 2017-09-03 20:11:31

How to determine the format of the message that came to the server - Json or just a string?

I want to send json messages to the server and just strings, numbers. How can I determine what format the message from the client carries?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
coxbrain, 2017-09-04
@coxbrain

You parse (unmarshal) as JSON, if there is an error, you consider it a simple string.

E
Evgeniy Ivakha, 2017-09-07
@ivahaev

Look at the HTTP header Content-Type . If there is application/json , then the output is obvious! If we are talking about an HTTP server, of course, but with others it is similar - there are service headers that determine the data format.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question