Legend

Class
Struct
Enum
Interface
Delegate
Constructor
Method
Property
Event
Field

Static method: string Fmt(string, params JsonValue[])

Declaration

public static string Fmt(
    string js,
    params JsonValue[] namevalues
)

Summary

Formats JSON values into a piece of JavaScript code and then removes almost all unnecessary whitespace and comments. Values are referenced by names; placeholders for these values are written as {{name}}. Placeholders are only replaced outside of JavaScript literal strings and regexes. JsonRaw instances are inserted unmodified.

Parameters

stringjs JavaScript code with placeholders.
JsonValue[]namevalues Alternating names and associated values, for example ["user", "abc"] specifies one value named "user".

Exceptions

  • System.ArgumentException
    namevalues has an odd number of values. OR js contains a {{placeholder}} whose name is not listed in namevalues.
  • System.ArgumentNullException
    js is null. OR namevalues is null.

Example

The following code:

JsonValue.Fmt(@"Foo({{userid}}, {{username}}, {{options}});",
    "userid", userid,
    "username", username,
    "options", null)

might return the following string:

Foo(123, "Matthew Stranger", null);