1 // Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 // WriteJSON writes the JSON encoding of v as a message.
14 // Deprecated: Use c.WriteJSON instead.
15 func WriteJSON(c *Conn, v interface{}) error {
19 // WriteJSON writes the JSON encoding of v as a message.
21 // See the documentation for encoding/json Marshal for details about the
22 // conversion of Go values to JSON.
23 func (c *Conn) WriteJSON(v interface{}) error {
24 w, err := c.NextWriter(TextMessage)
28 err1 := json.NewEncoder(w).Encode(v)
36 // ReadJSON reads the next JSON-encoded message from the connection and stores
37 // it in the value pointed to by v.
39 // Deprecated: Use c.ReadJSON instead.
40 func ReadJSON(c *Conn, v interface{}) error {
44 // ReadJSON reads the next JSON-encoded message from the connection and stores
45 // it in the value pointed to by v.
47 // See the documentation for the encoding/json Unmarshal function for details
48 // about the conversion of JSON to a Go value.
49 func (c *Conn) ReadJSON(v interface{}) error {
50 _, r, err := c.NextReader()
54 err = json.NewDecoder(r).Decode(v)
56 // One value is expected in the message.
57 err = io.ErrUnexpectedEOF