JSON returns a new Value instance with JSON contents of WebSocket message. JSON succeeds if JSON may be decoded from message content. Example: msg := conn.Expect() msg.JSON().Array().ConsistsOf("foo", "bar")
()
| 535 | // msg := conn.Expect() |
| 536 | // msg.JSON().Array().ConsistsOf("foo", "bar") |
| 537 | func (wm *WebsocketMessage) JSON() *Value { |
| 538 | opChain := wm.chain.enter("JSON()") |
| 539 | defer opChain.leave() |
| 540 | |
| 541 | if opChain.failed() { |
| 542 | return newValue(opChain, nil) |
| 543 | } |
| 544 | |
| 545 | var value interface{} |
| 546 | |
| 547 | if err := json.Unmarshal(wm.content, &value); err != nil { |
| 548 | opChain.fail(AssertionFailure{ |
| 549 | Type: AssertValid, |
| 550 | Actual: &AssertionValue{ |
| 551 | string(wm.content), |
| 552 | }, |
| 553 | Errors: []error{ |
| 554 | errors.New("failed to decode json"), |
| 555 | err, |
| 556 | }, |
| 557 | }) |
| 558 | return newValue(opChain, nil) |
| 559 | } |
| 560 | |
| 561 | return newValue(opChain, value) |
| 562 | } |
| 563 | |
| 564 | type wsMessageType int |
| 565 |