qs 0.0.2 copy "qs: ^0.0.2" to clipboard
qs: ^0.0.2 copied to clipboard

A query string encoding and encoding library. It's better to use with protobuf(go), gorilla/schema(go) and qs(js).

qs #

Encode json to query string or decode query string to json.

Encode #

void encode() {
  const json = {
    'key1': 11,
    'key2': 'str',
    'key3': false,
    'key4': 0,
    'key5': {'cKey1': true},
    'key6': [0, 1],
    'key7': [
      {'cKey1': 233},
      {'cKey2': false}
    ]
  };

  const result =
      'key_1=11&key_2=str&key_3=false&key_4=0&key_5.c_key_1=true&key_6=0&key_6=1&key_7.0.c_key_1=233&key_7.1.c_key_2=false';

  final encoder = qs.Encoder();
  final str = encoder.encode(json);

  print(result == str);
}

Decode #

void decode() {
  const str =
      'key_1=11&key_2=str&key_3=false&key_4=0&key_5.c_key_1=true&key_6=0&key_6=1&key_7.0.c_key_1=233&key_7.1.c_key_2=false';

  const result = {
    'key1': ['11'],
    'key2': ['str'],
    'key3': ['false'],
    'key4': ['0'],
    'key5': {
      'cKey1': ['true']
    },
    'key6': ['1'],
    'key7': [
      {
        'cKey1': ['233']
      },
      {
        'cKey2': ['false']
      }
    ]
  };

  final decoder = qs.Decoder();
  final json = decoder.decode(str);
  print(json == result);
}
1
likes
130
pub points
67%
popularity

Publisher

verified publisherronbb.fun

A query string encoding and encoding library. It's better to use with protobuf(go), gorilla/schema(go) and qs(js).

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

More

Packages that depend on qs