Cisco Cisco Prime Home 2.4 Developer's Guide
Cisco Prime Home – Integration Guide
OL-28557-01 v5.0.1
34
getObject(path.tail, child)
} else {
parent
}
getObject(path, jsonObject).put(path.last, value)
jsonObject }
/**
* Allows you to set an object property deep within a JSON
} else {
parent
}
getObject(path, jsonObject).put(path.last, value)
jsonObject }
/**
* Allows you to set an object property deep within a JSON
object tree.
* For example given: { x: { y: {} } }, you can call:
deepPut("x.y.z", "1") to
* yield { x: { y: { z: 1 } } }
* @param path a '.' separated path of to the property to
* @param path a '.' separated path of to the property to
set
* @return the resulting JSON object
*/
def deepPut(path: String, value: String): JSONObject =
*/
def deepPut(path: String, value: String): JSONObject =
deepPut(path.split('.').toList, value) }
/**
* A rich wrapper around a JSON array
* @param jsonObject the wrapped JSON object
*/
class RichJSONArray(jsonArray: JSONArray) {
/**
* Converts a JSON array to a list of json objects.
* A rich wrapper around a JSON array
* @param jsonObject the wrapped JSON object
*/
class RichJSONArray(jsonArray: JSONArray) {
/**
* Converts a JSON array to a list of json objects.
useful for
* arrays in the form: [{}, {}, ... {}]
*
* @return a list of JSON objects
*/
def toJSONObjectList(): List[JSONObject] = {
*
* @return a list of JSON objects
*/
def toJSONObjectList(): List[JSONObject] = {
var buffer = new ListBuffer[JSONObject]
for (ix <- 0 until jsonArray.length) buffer +=
for (ix <- 0 until jsonArray.length) buffer +=
jsonArray.getJSONObject(ix)
buffer.toList
}
}
/**
* An implicit conversion to the wrapped JSON object
*/
implicit def toRichJSONObject(jsonObject: JSONObject) = new
}
/**
* An implicit conversion to the wrapped JSON object
*/
implicit def toRichJSONObject(jsonObject: JSONObject) = new
RichJSONObject(jsonObject)
/**
* An implicit conversion to the wrapped JSON array
*/
implicit def toRichJSONArray(jsonArray: JSONArray) = new
RichJSONArray(jsonArray)
}
* An implicit conversion to the wrapped JSON array
*/
implicit def toRichJSONArray(jsonArray: JSONArray) = new
RichJSONArray(jsonArray)
}
Interacting with Search