Module: MultiJson::OkJson

### Home Classes Methods

### In Files

- lib/multi_json/vendor/okjson.rb

### Namespace

- CLASS MultiJson::OkJson::Error
- CLASS MultiJson::OkJson::Utf8Error

### Methods

- #decode
- #encode
- #valenc

### Class/Module Index

Quicksearch

- MultiJson
- MultiJson::Adapter
- MultiJson::AdapterError
- MultiJson::Adapters
- MultiJson::Adapters::Gson
- MultiJson::Adapters::JrJackson
- MultiJson::Adapters::JsonCommon
- MultiJson::Adapters::JsonGem
- MultiJson::Adapters::JsonPure
- MultiJson::Adapters::Nsjsonserialization
- MultiJson::Adapters::Oj
- MultiJson::Adapters::OkJson
- MultiJson::Adapters::Yajl
- MultiJson::ConvertibleHashKeys
- MultiJson::OkJson
- MultiJson::OkJson::Error
- MultiJson::OkJson::Utf8Error
- MultiJson::Options
- MultiJson::ParseError
- MultiJson::Version

No matching classes.

# MultiJson::OkJson

Some parts adapted from golang.org/src/pkg/json/decode.go and golang.org/src/pkg/utf8/utf8.go

### Constants

Spc
Uchar1max
Uchar2max
Uchar3max
Ucharerr
Umask2
Umask3
Umask4
Umaskx
Unesc
Upstream
Ustrerr
Usurr1
Usurr2
Usurr3
Usurrself
Utag2
Utag3
Utag4
Utag5
Utagx

### Public Instance Methods

decode(s) click to toggle source

Decodes a json document in string s and returns the corresponding ruby value. String s must be valid UTF-8. If you have a string in some other encoding, convert it first.

String values in the resulting structure will be UTF-8.

    # File lib/multi_json/vendor/okjson.rb, line 43
    def decode(s)
      ts = lex(s)
      v, ts = textparse(ts)
      if ts.length > 0
        raise Error, 'trailing garbage'
      end
      v
    end

encode(x) click to toggle source

Encodes x into a json text. It may contain only Array, Hash, String, Numeric, true, false, nil. (Note, this list excludes Symbol.) X itself must be an Array or a Hash. No other value can be encoded, and an error will be raised if x contains any other value, such as Nan, Infinity, Symbol, and Proc, or if a Hash key is not a String. Strings contained in x must be valid UTF-8.

    # File lib/multi_json/vendor/okjson.rb, line 62
    def encode(x)
      case x
      when Hash    then objenc(x)
      when Array   then arrenc(x)
      else
        raise Error, 'root value must be an Array or a Hash'
      end
    end

valenc(x) click to toggle source

    # File lib/multi_json/vendor/okjson.rb, line 72
    def valenc(x)
      case x
      when Hash    then objenc(x)
      when Array   then arrenc(x)
      when String  then strenc(x)
      when Numeric then numenc(x)
      when true    then "true"
      when false   then "false"
      when nil     then "null"
      else
        if x.respond_to?(:to_json)
          x.to_json
        else
          raise Error, "cannot encode #{x.class}: #{x.inspect}"
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.