Package com.yahoo.text
Class JSON
- java.lang.Object
-
- com.yahoo.text.JSON
-
public final class JSON extends java.lang.Object
Static methods for working with JSON.- Author:
- bratseth
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
encode(java.util.Map<java.lang.String,?> map)
Outputs a map as a JSON 'object' string, provided that the map values are either String Number Any object whose toString returns JSONstatic boolean
equals(java.lang.String left, java.lang.String right)
Test whether two JSON strings are equal, e.g.static java.lang.String
escape(java.lang.String s)
Returns the given string as a properly json escaped string
-
-
-
Method Detail
-
encode
public static java.lang.String encode(java.util.Map<java.lang.String,?> map)
Outputs a map as a JSON 'object' string, provided that the map values are either- String
- Number
- Any object whose toString returns JSON
-
escape
public static java.lang.String escape(java.lang.String s)
Returns the given string as a properly json escaped string
-
equals
public static boolean equals(java.lang.String left, java.lang.String right)
Test whether two JSON strings are equal, e.g. the order of fields in an object is irrelevant.When comparing two numbers of the two JSON strings, the result is only guaranteed to be correct if (a) both are integers (without fraction and exponent) and each fits in a long, or (b) both are non-integers, fits in a double, and are syntactically identical. Examples of pairs that may not be equal: 1 and 1.0 (different types), 0.1 and 1e-1, 0.0 and 0.00.
- Throws:
java.lang.RuntimeException
- on invalid JSON
-
-