public class ReadWriteJSON
extends java.lang.Object
JSONObject
.Constructor and Description |
---|
ReadWriteJSON()
Create a new instance of ReadWriteJSON
|
Modifier and Type | Method and Description |
---|---|
void |
changeValue(java.lang.String tknName,
java.lang.Object tknValue,
JSONObject jsonObj)
Change or set the json script value with the specified name.
|
java.lang.Object |
getValue(java.lang.String tknName,
JSONObject jsonObj)
Get the json script value with the specified name.
|
JSONObject |
readData(java.io.FileReader fileReader)
Read an entire json script from a data file.
|
JSONObject |
readData(java.lang.String jsonStr)
Read an entire json script from a data string.
|
void |
setValue(java.lang.String tknName,
java.lang.Object tknValue,
JSONObject jsonObj)
Set the json script value with the specified name.
|
void |
writeData(JSONObject jsonObj,
java.io.FileWriter file)
Write an entire json script to a file.
|
void |
writeData(JSONObject jsonObj,
java.lang.String filePath)
Write an entire json script to a file.
|
public JSONObject readData(java.io.FileReader fileReader) throws java.lang.Exception
fileReader
- the file reader.java.lang.Exception
- any error.public JSONObject readData(java.lang.String jsonStr) throws java.lang.Exception
jsonStr
- the data string.java.lang.Exception
- any error.public void writeData(JSONObject jsonObj, java.lang.String filePath) throws java.lang.Exception
jsonObj
- the json object.filePath
- the full file path.java.lang.Exception
- any error.public void writeData(JSONObject jsonObj, java.io.FileWriter file) throws java.lang.Exception
jsonObj
- the json object.file
- the file to write to.java.lang.Exception
- any error.public void changeValue(java.lang.String tknName, java.lang.Object tknValue, JSONObject jsonObj) throws java.lang.Exception
tknName
- the variable name.tknValue
- the object value. This overwrites any existing value.jsonObj
- the variable value.java.lang.Exception
- any error.public void setValue(java.lang.String tknName, java.lang.Object tknValue, JSONObject jsonObj) throws java.lang.Exception
tknName
- the variable name.tknValue
- the object value. If the variable already exists, it gets converted into a
JSONArray
first and then the new value is added to that.jsonObj
- the variable value.java.lang.Exception
- any error.public java.lang.Object getValue(java.lang.String tknName, JSONObject jsonObj) throws java.lang.Exception
tknName
- the variable name.jsonObj
- the script object with that name. Can be a list of type JSONArray
.java.lang.Exception
- any error.