本文整理汇总了Java中com.google.gwt.json.client.JSONObject类的典型用法代码示例。如果您正苦于以下问题:Java JSONObject类的具体用法?Java JSONObject怎么用?Java JSONObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JSONObject类属于com.google.gwt.json.client包,在下文中一共展示了JSONObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getState
import com.google.gwt.json.client.JSONObject; //导入依赖的package包/类
public JSONArray getState() {
JSONObject states = new JSONObject();
for (IModule currModule : modules) {
if (currModule instanceof StatefulModule) {
StatefulModule statefulModule = (StatefulModule) currModule;
states.put(statefulModule.getIdentifier(), statefulModule.getState());
}
}
JSONArray statesArr = new JSONArray();
statesArr.set(0, states);
return statesArr;
}
示例2: testShouldReturnIdentifierFromState
import com.google.gwt.json.client.JSONObject; //导入依赖的package包/类
public void testShouldReturnIdentifierFromState() throws Exception {
// given
String givenState = "givenState";
String identifier = "identifier";
JSONObject givenStateObject = new JSONObject();
givenStateObject.put(EmpiriaState.STATE, new JSONString(givenState));
givenStateObject.put(EmpiriaState.LESSON_IDENTIFIER, new JSONString(identifier));
givenStateObject.put(EmpiriaState.TYPE, new JSONString("LZ_GWT"));
// when
EmpiriaState result = testObj.deserialize(givenStateObject);
// then
assertEquals(result.getState(), givenState);
assertEquals(result.getLessonIdentifier(), identifier);
}
示例3: shouldDecompressState_whileCreating
import com.google.gwt.json.client.JSONObject; //导入依赖的package包/类
@Test
public void shouldDecompressState_whileCreating() throws Exception {
// GIVEN
String givenState = "state";
String expectedState = "compressed";
JSONObject parsedState = new JSONObject();
when(jsonParser.parse(givenState)).thenReturn(parsedState);
EmpiriaState empiriaState = new EmpiriaState(EmpiriaStateType.LZ_GWT, givenState, "id");
when(empiriaStateVerifier.verifyState(empiriaState)).thenReturn(empiriaState);
when(empiriaStateDeserializer.deserialize(parsedState)).thenReturn(empiriaState);
when(lzGwtWrapper.decompress(givenState)).thenReturn(expectedState);
// WHEN
String result = testObj.createState(givenState);
// THEN
assertThat(result).isEqualTo(expectedState);
}
示例4: shouldReturnEmptyState_whenStateIsUnknown
import com.google.gwt.json.client.JSONObject; //导入依赖的package包/类
@Test
public void shouldReturnEmptyState_whenStateIsUnknown() throws Exception {
// GIVEN
String givenState = "state";
JSONObject parsedState = new JSONObject();
when(jsonParser.parse(givenState)).thenReturn(parsedState);
EmpiriaState empiriaState = new EmpiriaState(EmpiriaStateType.UNKNOWN, givenState, StringUtils.EMPTY);
when(empiriaStateVerifier.verifyState(empiriaState)).thenReturn(empiriaState);
when(empiriaStateDeserializer.deserialize(parsedState)).thenReturn(empiriaState);
// WHEN
String result = testObj.createState(givenState);
// THEN
assertThat(result).isEmpty();
}
示例5: shouldDoNothingWithState_whenStateHasOldType
import com.google.gwt.json.client.JSONObject; //导入依赖的package包/类
@Test
public void shouldDoNothingWithState_whenStateHasOldType() throws Exception {
// GIVEN
String givenState = "state";
JSONObject parsedState = new JSONObject();
when(jsonParser.parse(givenState)).thenReturn(parsedState);
EmpiriaState empiriaState = new EmpiriaState(EmpiriaStateType.OLD, givenState, StringUtils.EMPTY);
when(empiriaStateVerifier.verifyState(empiriaState)).thenReturn(empiriaState);
when(empiriaStateDeserializer.deserialize(parsedState)).thenReturn(empiriaState);
// WHEN
String result = testObj.createState(givenState);
// THEN
assertThat(result).isEqualTo(givenState);
verify(lzGwtWrapper, never()).decompress(givenState);
}
示例6: testShouldGetStateObject
import com.google.gwt.json.client.JSONObject; //导入依赖的package包/类
public void testShouldGetStateObject() {
// given
JavaScriptObject state = JavaScriptObject.createObject();
JSONArray stateArray = new JSONArray();
stateArray.set(0, new JSONObject(state));
JSONObject stateObject = new JSONObject();
stateObject.put("STATE", stateArray);
JSONArray jsonArray = new JSONArray();
jsonArray.set(0, stateObject);
// when
JavaScriptObject result = testObj.decodeState(jsonArray);
// then
assertEquals(result, state);
}
示例7: testSetStateOnFirstModuleOnly
import com.google.gwt.json.client.JSONObject; //导入依赖的package包/类
public void testSetStateOnFirstModuleOnly() { // given //
// given
// @formatter:off
String stateString = "{\"" +
FIRST_IDENTIFIER + "\":" + FIRST_STATE +
"}";
// @formatter:on
JSONObject stateObject = getStateObjectByString(stateString);
JSONArray state = getJSONArrayWithObject(stateObject);
// when
loader.setState(state, modules);
// then
assertEquals(stateObject.get(FIRST_IDENTIFIER).isArray(), firstModule.getState());
assertNull(secondModule.getState());
}
示例8: testSetStateOnTwoModules
import com.google.gwt.json.client.JSONObject; //导入依赖的package包/类
public void testSetStateOnTwoModules() {
// given
// @formatter:off
String stateString = "{\"" +
FIRST_IDENTIFIER + "\":" + FIRST_STATE + ", \"" +
SECOND_IDENTIFIER + "\":" + SECOND_STATE +
"}";
// @formatter:on
JSONObject stateObject = getStateObjectByString(stateString);
JSONArray state = getJSONArrayWithObject(stateObject);
// when
loader.setState(state, modules);
// then
assertEquals(stateObject.get(FIRST_IDENTIFIER).isArray(), firstModule.getState());
assertEquals(stateObject.get(SECOND_IDENTIFIER).isArray(), secondModule.getState());
}
示例9: toJSON
import com.google.gwt.json.client.JSONObject; //导入依赖的package包/类
public String toJSON() {
JSONObject projectObject = new JSONObject();
projectObject.put("version", new JSONString(getVersion()));
projectObject.put("title", new JSONString(getTitle()));
projectObject.put("description", new JSONString(getDescription()));
projectObject.put("date", new JSONString(getDate()));
JSONArray layersArray = new JSONArray();
int index = 0;
for(ProjectVectorLayer projectLayer: vectors) {
layersArray.set(index, projectLayer.getJSONObject());
index++;
}
projectObject.put("vectors", layersArray);
return projectObject.toString();
}
示例10: getStyle
import com.google.gwt.json.client.JSONObject; //导入依赖的package包/类
public static ProjectLayerStyle getStyle(String geoJSONCSS) {
ProjectLayerStyle style = null;
final JSONValue jsonValue = JSONParser.parseLenient(geoJSONCSS);
final JSONObject geoJSONCssObject = jsonValue.isObject();
if (geoJSONCssObject.containsKey(GeoJSONCSS.STYLE_NAME)) {
JSONObject styleObject = geoJSONCssObject
.get(GeoJSONCSS.STYLE_NAME).isObject();
String fillColor = getStringValue(styleObject, FILL_COLOR_NAME);
Double fillOpacity = getDoubleValue(styleObject, FILL_OPACITY_NAME);
if(fillOpacity == null) {
fillOpacity = getDoubleValue(styleObject, FILL_OPACITY2_NAME);
}
String strokeColor = getStringValue(styleObject, STROKE_COLOR_NAME);
Double strokeWidth = getDoubleValue(styleObject, STROKE_WIDTH_NAME);
style = new ProjectLayerStyle(fillColor, fillOpacity, strokeColor,
strokeWidth);
}
return style;
}
示例11: extractFormName
import com.google.gwt.json.client.JSONObject; //导入依赖的package包/类
private static String extractFormName(RpcResult result) {
String extraString = result.getExtra();
if (extraString != null) {
JSONValue extraJSONValue = JSONParser.parseStrict(extraString);
JSONObject extraJSONObject = extraJSONValue.isObject();
if (extraJSONObject != null) {
JSONValue formNameJSONValue = extraJSONObject.get("formName");
if (formNameJSONValue != null) {
JSONString formNameJSONString = formNameJSONValue.isString();
if (formNameJSONString != null) {
return formNameJSONString.stringValue();
}
}
}
}
return "Screen1";
}
示例12: applyAlphaMapMaterial
import com.google.gwt.json.client.JSONObject; //导入依赖的package包/类
public void applyAlphaMapMaterial(Primitive primitive) {
JSONObject uniforms = new JSONObject();
uniforms.put("image", new JSONString(GWT.getModuleBaseURL() + "images/Cesium_Logo_Color.jpg"));
uniforms.put("channel", new JSONString("r"));
JSONObject alphaMaterial = new JSONObject();
alphaMaterial.put("type", new JSONString("AlphaMap"));
alphaMaterial.put("uniforms", uniforms);
JSONObject materials = new JSONObject();
materials.put("alphaMaterial", alphaMaterial);
JSONObject components = new JSONObject();
components.put("diffuse", new JSONString("vec3(1.0)"));
components.put("alpha", new JSONString("alphaMaterial.alpha"));
JSONObject fabric = new JSONObject();
fabric.put("materials", materials);
fabric.put("components", components);
MaterialOptions materialOptions = new MaterialOptions();
materialOptions.fabric = JsonUtils.safeEval(fabric.toString());
primitive.appearance.material = new Material(materialOptions);
}
示例13: applyWaterMaterial
import com.google.gwt.json.client.JSONObject; //导入依赖的package包/类
public void applyWaterMaterial(Primitive primitive) {
JSONObject uniforms = new JSONObject();
uniforms.put("specularMap", new JSONString(GWT.getModuleBaseURL() + "images/earthspec1k.jpg"));
uniforms.put("normalMap", new JSONString(GWT.getModuleBaseURL() + "images/waterNormals.jpg"));
uniforms.put("frequency", new JSONNumber(10000.0));
uniforms.put("animationSpeed", new JSONNumber(0.01));
uniforms.put("amplitude", new JSONNumber(1.0));
JSONObject fabric = new JSONObject();
fabric.put("type", new JSONString("Water"));
fabric.put("uniforms", uniforms);
MaterialOptions materialOptions = new MaterialOptions();
materialOptions.fabric = JsonUtils.safeEval(fabric.toString());
primitive.appearance.material = new Material(materialOptions);
}
示例14: setOption
import com.google.gwt.json.client.JSONObject; //导入依赖的package包/类
private void setOption(JSONObject rootObject, String path, Object value) {
if (path == null) {
return;
}
if (path.startsWith("/")) {
path = path.substring(1);
}
if (path.length() <= 0) {
return;
}
String nodeName = path;
if (nodeName.contains("/")) {
nodeName = nodeName.substring(0, nodeName.indexOf("/"));
JSONValue objectAsValue = rootObject.get(nodeName);
if (objectAsValue == null || objectAsValue.isObject() == null) {
rootObject.put(nodeName, new JSONObject());
}
JSONObject object = (JSONObject) rootObject.get(nodeName);
setOption(object, path.substring(path.indexOf("/") + 1), value);
} else {
rootObject.put(nodeName, convertToJSONValue(value));
}
}
示例15: parseDefaultValues
import com.google.gwt.json.client.JSONObject; //导入依赖的package包/类
/**
* Extracts default preference values from the gadget metadata JSON object
* returned from GGS.
*
* @param prefs the preference JSON object received from GGS.
*/
public void parseDefaultValues(JSONObject prefs) {
if (prefs != null) {
for (String pref : prefs.keySet()) {
if (!has(pref)) {
JSONObject prefJson = prefs.get(pref).isObject();
if (prefJson != null) {
JSONValue value = prefJson.get("default");
if ((value != null) && (value.isString() != null)) {
put(pref, value.isString().stringValue());
log("Gadget pref '" + pref + "' = '" + get(pref) + "'");
}
} else {
log("Invalid pref '" + pref + "' value in Gadget metadata.");
}
}
}
}
}