Module org.jfree.chart3d
Package org.jfree.chart3d.data

# Class JSONUtils

java.lang.Object
org.jfree.chart3d.data.JSONUtils

public class JSONUtils extends Object
Utility methods for interchange between datasets (`KeyedValues`, `KeyedValues3D` and `XYZDataset`) and JSON format strings.

Since:
  1.3

## Constructor Summary

Constructors
Constructor
Description
`JSONUtils()`

## Method Summary

Modifier and Type
Method
Description
`static KeyedValues<String,Number>`
`readKeyedValues(Reader reader)`
Parses characters from the supplied reader and returns the corresponding `KeyedValues` instance.
`static KeyedValues<String,Number>`
`readKeyedValues(String json)`
Parses the supplied JSON string into a `KeyedValues` instance.
`static KeyedValues2D<String,String,Number>`
`readKeyedValues2D(Reader reader)`
Reads a data table from a JSON format string coming from the specified reader.
`static KeyedValues2D<String,String,Number>`
`readKeyedValues2D(String json)`
Reads a data table from a JSON format string.
`static KeyedValues3D<String,String,String,Number>`
`readKeyedValues3D(Reader reader)`
Parses character data from the reader and (if possible) creates a `KeyedValues3D` instance.
`static KeyedValues3D<String,String,String,Number>`
`readKeyedValues3D(String json)`
Parses the supplied string and (if possible) creates a `KeyedValues3D` instance.
`static XYZDataset<String>`
`readXYZDataset(Reader reader)`
Parses character data from the reader and (if possible) creates an {XYZDataset} instance that represents the data.
`static XYZDataset<String>`
`readXYZDataset(String json)`
Parses the string and (if possible) creates an {XYZDataset} instance that represents the data.
`static String`
`writeKeyedValues(KeyedValues data)`
Returns a string containing the data in JSON format.
`static void`
`writeKeyedValues(KeyedValues data, Writer writer)`
Writes the data in JSON format to the supplied writer.
`static String`
`writeKeyedValues2D(KeyedValues2D data)`
Writes a data table to a string in JSON format.
`static void`
`writeKeyedValues2D(KeyedValues2D data, Writer writer)`
Writes the data in JSON format to the supplied writer.
`static String`
`writeKeyedValues3D(KeyedValues3D dataset)`
Returns a string containing the data in JSON format.
`static void`
`writeKeyedValues3D(KeyedValues3D dataset, Writer writer)`
Writes the dataset in JSON format to the supplied writer.
`static String`
`writeXYZDataset(XYZDataset dataset)`
Returns a string containing the dataset in JSON format.
`static void`
`writeXYZDataset(XYZDataset dataset, Writer writer)`
Writes the dataset in JSON format to the supplied writer.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### JSONUtils

public JSONUtils()

## Method Details

### readKeyedValues

public static KeyedValues<String,Number> readKeyedValues(String json)
Parses the supplied JSON string into a `KeyedValues` instance.
Implementation note: this method returns an instance of `StandardPieDataset3D`).

Parameters:
  `json` - the JSON string (`null` not permitted).
Returns:
  A `KeyedValues` instance.

### readKeyedValues

public static KeyedValues<String,Number> readKeyedValues(Reader reader) throws IOException
Parses characters from the supplied reader and returns the corresponding `KeyedValues` instance.
Implementation note: this method returns an instance of `StandardPieDataset3D`).

Parameters:
  `reader` - the reader (`null` not permitted).
Returns:
  A `KeyedValues` instance.
Throws:
  `IOException` - if there is an I/O problem.

### writeKeyedValues

public static String writeKeyedValues(KeyedValues data)
Returns a string containing the data in JSON format. The format is an array of arrays, where each sub-array represents one data value. The sub-array should contain two items, first the item key as a string and second the item value as a number. For example: `[["Key A", 1.0], ["Key B", 2.0]]`
Note that this method can be used with instances of `PieDataset3D`.

Parameters:
  `data` - the data (`null` not permitted).
Returns:
  A string in JSON format.

### writeKeyedValues

public static void writeKeyedValues(KeyedValues data, Writer writer) throws IOException
Writes the data in JSON format to the supplied writer.
Note that this method can be used with instances of `PieDataset3D`.

Parameters:
  `data` - the data (`null` not permitted).
  `writer` - the writer (`null` not permitted).
Throws:
  `IOException` - if there is an I/O problem.

### readKeyedValues2D

public static KeyedValues2D<String,String,Number> readKeyedValues2D(String json)
Reads a data table from a JSON format string.

Parameters:
  `json` - the string (`null` not permitted).
Returns:
  A data table.

### readKeyedValues2D

public static KeyedValues2D<String,String,Number> readKeyedValues2D(Reader reader) throws IOException
Reads a data table from a JSON format string coming from the specified reader.

Parameters:
  `reader` - the reader (`null` not permitted).
Returns:
  A data table.
Throws:
  `IOException` - if there is an I/O problem.

### writeKeyedValues2D

public static String writeKeyedValues2D(KeyedValues2D data)
Writes a data table to a string in JSON format.

Parameters:
  `data` - the data (`null` not permitted).
Returns:
  The string.

### writeKeyedValues2D

public static void writeKeyedValues2D(KeyedValues2D data, Writer writer) throws IOException
Writes the data in JSON format to the supplied writer.

Parameters:
  `data` - the data (`null` not permitted).
  `writer` - the writer (`null` not permitted).
Throws:
  `IOException` - if there is an I/O problem.

### readKeyedValues3D

public static KeyedValues3D<String,String,String,Number> readKeyedValues3D(String json)
Parses the supplied string and (if possible) creates a `KeyedValues3D` instance.

Parameters:
  `json` - the JSON string (`null` not permitted).
Returns:
  A `KeyedValues3D` instance.

### readKeyedValues3D

public static KeyedValues3D<String,String,String,Number> readKeyedValues3D(Reader reader) throws IOException
Parses character data from the reader and (if possible) creates a `KeyedValues3D` instance. This method will read back the data written by `writeKeyedValues3D(org.jfree.chart3d.data.KeyedValues3D, java.io.Writer)`.

Parameters:
  `reader` - the reader (`null` not permitted).
Returns:
  A `KeyedValues3D` instance.
Throws:
  `IOException` - if there is an I/O problem.

### writeKeyedValues3D

public static String writeKeyedValues3D(KeyedValues3D dataset)
Returns a string containing the data in JSON format.

Parameters:
  `dataset` - the data (`null` not permitted).
Returns:
  A string in JSON format.

### writeKeyedValues3D

public static void writeKeyedValues3D(KeyedValues3D dataset, Writer writer) throws IOException
Writes the dataset in JSON format to the supplied writer.

Parameters:
  `dataset` - the dataset (`null` not permitted).
  `writer` - the writer (`null` not permitted).
Throws:
  `IOException` - if there is an I/O problem.

### readXYZDataset

public static XYZDataset<String> readXYZDataset(String json)
Parses the string and (if possible) creates an {XYZDataset} instance that represents the data. This method will read back the data that is written by `writeXYZDataset(org.jfree.chart3d.data.xyz.XYZDataset)`.

Parameters:
  `json` - a JSON formatted string (`null` not permitted).
Returns:
  A dataset.
See Also:
  - `writeXYZDataset(org.jfree.chart3d.data.xyz.XYZDataset)`

### readXYZDataset

public static XYZDataset<String> readXYZDataset(Reader reader) throws IOException
Parses character data from the reader and (if possible) creates an {XYZDataset} instance that represents the data.

Parameters:
  `reader` - a reader (`null` not permitted).
Returns:
  A dataset.
Throws:
  `IOException` - if there is an I/O problem.

### writeXYZDataset

public static String writeXYZDataset(XYZDataset dataset)
Returns a string containing the dataset in JSON format.

Parameters:
  `dataset` - the dataset (`null` not permitted).
Returns:
  A string in JSON format.

### writeXYZDataset

public static void writeXYZDataset(XYZDataset dataset, Writer writer) throws IOException
Writes the dataset in JSON format to the supplied writer.

Parameters:
  `dataset` - the data (`null` not permitted).
  `writer` - the writer (`null` not permitted).
Throws:
  `IOException` - if there is an I/O problem.