Java源码示例:com.google.gwt.json.client.JSONParser
示例1
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";
}
示例2
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;
}
示例3
@Override
public List<GadgetInfo> parseGadgetInfoJson(String json) {
List<GadgetInfo> gadgetList = new ArrayList<GadgetInfo>();
JSONValue value = JSONParser.parseStrict(json);
JSONArray array = value.isArray();
if (array != null) {
for (int i = 0; i < array.size(); i++) {
JSONValue item = array.get(i);
GadgetInfo info = parseGadgetInfo(item);
if (info != null) {
gadgetList.add(info);
}
}
}
return gadgetList;
}
示例4
@Override
public List<GadgetInfo> parseGadgetInfoJson(String json) {
List<GadgetInfo> gadgetList = new ArrayList<GadgetInfo>();
JSONValue value = JSONParser.parseStrict(json);
JSONArray array = value.isArray();
if (array != null) {
for (int i = 0; i < array.size(); i++) {
JSONValue item = array.get(i);
GadgetInfo info = parseGadgetInfo(item);
if (info != null) {
gadgetList.add(info);
}
}
}
return gadgetList;
}
示例5
public List<BootstrapServer> load() {
List<BootstrapServer> servers = new ArrayList<BootstrapServer>();
if (storage != null) {
//noinspection MismatchedQueryAndUpdateOfCollection
StorageMap storageMap = new StorageMap(storage);
if (storageMap.containsKey(KEY)) {
String json = storageMap.get(KEY);
if (json != null) {
JSONValue jsonValue = JSONParser.parseStrict(json);
if (jsonValue != null) {
JSONArray jsonArray = jsonValue.isArray();
if (jsonArray != null) {
for (int i = 0; i < jsonArray.size(); i++) {
AutoBean<BootstrapServer> bean = AutoBeanCodex
.decode(factory, BootstrapServer.class, jsonArray.get(i).toString());
servers.add(bean.as());
}
}
}
}
}
}
return servers;
}
示例6
public BootstrapServer restoreSelection() {
if (storage != null) {
//noinspection MismatchedQueryAndUpdateOfCollection
StorageMap storageMap = new StorageMap(storage);
if (storageMap.containsKey(KEY)) {
String json = storageMap.get(SELECTED);
if (json != null) {
JSONValue jsonValue = JSONParser.parseStrict(json);
if (jsonValue != null) {
JSONObject jsonObject = jsonValue.isObject();
if (jsonObject != null) {
AutoBean<BootstrapServer> bean = AutoBeanCodex
.decode(factory, BootstrapServer.class, jsonObject.toString());
return bean.as();
}
}
}
}
}
return null;
}
示例7
/**
* Sets the dynamic template Urls from a jsonStr. This method is
* called during start up where jsonStr is retrieved from User
* settings.
*
* @param jsonStr
*/
public static void setStoredTemplateUrls(String jsonStr) {
if (jsonStr == null || jsonStr.length() == 0)
return;
JSONValue jsonVal = JSONParser.parseLenient(jsonStr);
JSONArray jsonArr = jsonVal.isArray();
for (int i = 0; i < jsonArr.size(); i++) {
JSONValue value = jsonArr.get(i);
JSONString str = value.isString();
dynamicTemplateUrls.add(str.stringValue());
}
}
示例8
/**
* Returns a list of Template objects containing data needed
* to load a template from a zip file. Each non-null template object
* is created from its Json string
*
* @return ArrayList of TemplateInfo objects
*/
protected static ArrayList<TemplateInfo> getTemplates() {
JSONValue jsonVal = JSONParser.parseLenient(templateDataString);
JSONArray jsonArr = jsonVal.isArray();
ArrayList<TemplateInfo> templates = new ArrayList<TemplateInfo>();
for (int i = 0; i < jsonArr.size(); i++) {
JSONValue value = jsonArr.get(i);
JSONObject obj = value.isObject();
if (obj != null)
templates.add(new TemplateInfo(obj)); // Create TemplateInfo from Json
}
return templates;
}
示例9
/**
* getSubsetDrawerNames
* @param form
* @return array of built-in block drawers for the blocks editor that contain blocks included in
* the subset parameter. This keeps empty drawers from displaying in the Blocks Editor
*/
private Set<String> getSubsetDrawerNames(MockForm form) {
String subsetJsonString = form.getPropertyValue(SettingsConstants.YOUNG_ANDROID_SETTINGS_BLOCK_SUBSET);
if (subsetJsonString.length() > 0) {
JSONObject subsetJSON = JSONParser.parseStrict(subsetJsonString).isObject();
Set<String> subsetDrawers = new HashSet<String>(subsetJSON.get("shownBlockTypes").isObject().keySet());
subsetDrawers.retainAll(BUILTIN_DRAWER_NAMES);
return subsetDrawers;
} else {
return BUILTIN_DRAWER_NAMES;
}
}
示例10
/**
* GWTFileUploadResponse
*
* @param text json encoded parameters.
*/
public GWTFileUploadResponse(String text) {
text = text.substring(text.indexOf("{"));
text = text.substring(0, text.lastIndexOf("}") + 1);
JSONValue responseValue = JSONParser.parseStrict(text);
JSONObject response = responseValue.isObject();
// Deserialize information
hasAutomation = response.get("hasAutomation").isBoolean().booleanValue();
path = URL.decodeQueryString(response.get("path").isString().stringValue());
error = response.get("error").isString().stringValue();
showWizardCategories = response.get("showWizardCategories").isBoolean().booleanValue();
showWizardKeywords = response.get("showWizardKeywords").isBoolean().booleanValue();
digitalSignature = response.get("digitalSignature").isBoolean().booleanValue();
// Getting property groups
JSONArray groupsArray = response.get("groupsList").isArray();
if (groupsArray != null) {
for (int i = 0; i <= groupsArray.size() - 1; i++) {
groupsList.add(groupsArray.get(i).isString().stringValue());
}
}
// Getting workflows
JSONArray workflowArray = response.get("workflowList").isArray();
if (workflowArray != null) {
for (int i = 0; i <= workflowArray.size() - 1; i++) {
workflowList.add(workflowArray.get(i).isString().stringValue());
}
}
}
示例11
/**
* Creates response object from JSON response string in
* {@link com.smartgwt.client.data.RestDataSource SmartGWT format}.
* @param response JSON response string
* @return response object
*/
public static DSResponse getDsResponse(String response) {
DSResponse dsResponse;
// ClientUtils.info(LOG, "response: %s", response);
if (response == null || response.isEmpty()) {
// not JSON response
LOG.log(Level.WARNING, null, new IllegalStateException("Empty response!"));
dsResponse = new DSResponse();
dsResponse.setStatus(RPCResponse.STATUS_SUCCESS);
} else {
JSONValue rVal = JSONParser.parseStrict(response);
if (rVal.isObject() != null) {
rVal = rVal.isObject().get("response");
}
if (rVal != null && rVal.isObject() != null) {
JSONObject rObj = rVal.isObject();
dsResponse = DSResponse.getOrCreateRef(rObj.getJavaScriptObject());
} else {
// not JSON response in expected format
JSONObject jsonObject = new JSONObject();
jsonObject.put("data", new JSONString(response));
dsResponse = new DSResponse(jsonObject.getJavaScriptObject());
dsResponse.setStatus(RPCResponse.STATUS_FAILURE);
}
}
return dsResponse;
}
示例12
public static JSONValue parse(String token) {
try {
if (JsonUtils.safeToEval(token)) {
JSONValue jsonv = JSONParser.parseStrict(token);
return jsonv;
}
} catch (Exception ex) {
LOG.log(Level.SEVERE, token, ex);
}
return null;
}
示例13
public Project(String json) {
final JSONValue jsonValue = JSONParser.parseLenient(json);
final JSONObject jsonObject = jsonValue.isObject();
String projectDate = jsonObject.get(DATE_NAME).isString().stringValue();
String projectTitle = jsonObject.get(TITLE_NAME).isString().stringValue();
String projectVersion = jsonObject.get(VERSION_NAME).isString().stringValue();
String projectDescription = jsonObject.get(DESCRIPTION_NAME).isString().stringValue();
setDate(projectDate);
setTitle(projectTitle);
setVersion(projectVersion);
setDescription(projectDescription);
JSONArray layersArray = jsonObject.get(VECTORS_NAME).isArray();
if (layersArray != null) {
for (int i = 0; i < layersArray.size(); i++) {
JSONObject projectLayerObj = layersArray.get(i).isObject();
String name = projectLayerObj.get(NAME).isString().stringValue();
String content = projectLayerObj.get(CONTENT_NAME).isString().stringValue();
JSONObject styleProjectLayer = projectLayerObj.get(STYLE_NAME).isObject();
String fillColor = styleProjectLayer.get(ProjectLayerStyle.FILL_COLOR_NAME).isString().stringValue();
Double fillOpacity = styleProjectLayer.get(ProjectLayerStyle.FILL_OPACITY_NAME).isNumber().doubleValue();
String strokeColor = styleProjectLayer.get(ProjectLayerStyle.STROKE_COLOR_NAME).isString().stringValue();
Double strokeWidth = styleProjectLayer.get(ProjectLayerStyle.STROKE_WIDTH_NAME).isNumber().doubleValue();
add(name, content, fillColor, fillOpacity, strokeColor, strokeWidth);
}
}
}
示例14
public VectorStyleDef getLayerStyle(String vectorFormatString) {
VectorFeatureStyleDef def = null;
final JSONValue jsonValue = JSONParser.parseLenient(vectorFormatString);
final JSONObject geoJSONCssObject = jsonValue.isObject();
if (geoJSONCssObject.containsKey(GeoJSONCSS.STYLE_NAME)) {
JSONObject styleObject = geoJSONCssObject.get(GeoJSONCSS.STYLE_NAME).isObject();
JSObject styleJSObject = styleObject.getJavaScriptObject().cast();
def = getStyleDef(styleJSObject);
}
return def;
}
示例15
private void handleCompleteJson(String reponseData) {
if (Strings.isNullOrEmpty(reponseData)) {
handleError("500", "Unable to post data");
}
JSONObject jsObject = JSONParser.parseLenient(reponseData).isObject();
final FileDto file = new FileDto();
file.setName(jsObject.get("name").isString().stringValue());
file.setExtension(jsObject.get("extension").isString().stringValue());
file.setMime(jsObject.get("mime").isString().stringValue());
file.setToken(jsObject.get("token").isString().stringValue());
file.setContentLength((long) jsObject.get("contentLength").isNumber().doubleValue());
if (this.uploadForm != null) {
this.uploadForm = this.uploadForm.destroy();
}
this.sendRequest = null;
this.fileId = null;
this.progressBar.edit(this.progressBar.getMax());
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
@Override
public boolean execute() {
InputFile.this.edit(file);
return false;
}
}, this.params.inputFileProgressHideDelay());
}
示例16
@Override
public void execute(Control<BootstrapContext> control) {
TextResource compat = TextResources.INSTANCE.compat();
JSONValue root = JSONParser.parseLenient(compat.getText());
JSONObject versionList = root.isObject();
Set<String> keys = versionList.keySet();
for (String key : keys) {
modelVersions.put(key, versionList.get(key).isString().stringValue());
}
System.out.println("Build against Core Model Version: " + modelVersions.get("core-version"));
control.proceed();
}
示例17
@Override
public ModelNode get() {
ModelNode node;
if (contentType.startsWith(APPLICATION_DMR_ENCODED)) {
node = ModelNode.fromBase64(payload);
} else if (contentType.startsWith(APPLICATION_JSON)) {
node = new ModelNode();
JSONObject response = JSONParser.parseLenient(payload).isObject();
JSONString outcome = response.get(OUTCOME).isString();
node.get(OUTCOME).set(outcome.stringValue());
if (outcome.stringValue().equals(SUCCESS)) {
if (response.containsKey(RESULT) && response.get(RESULT).isObject() != null) {
node.get(RESULT).set(stringify(response.get(RESULT).isObject().getJavaScriptObject(), 2));
} else {
node.get(RESULT).set(new ModelNode());
}
} else {
String failure = extractFailure(response);
node.get(FAILURE_DESCRIPTION).set(failure);
}
} else {
node = new ModelNode();
node.get(OUTCOME).set(FAILED);
node.get(FAILURE_DESCRIPTION).set("Unable to parse response with content-type " + contentType);
}
return node;
}
示例18
public void callLoadGlobalBlocks(String jsonStr) {
JSONObject jsonObj = JSONParser.parseStrict(jsonStr).isObject();
INSTANCE.loadComponents(jsonObj);
INSTANCE.loadGlobalBlocks(jsonObj);
}
示例19
private void getW3WPosition(final String words) {
startProgressBar();
w3wServiceAsync.getPosition(words, w3wTool.getLocale(), new AsyncCallback<String>() {
public void onFailure(final Throwable caught) {
finishProgressBar();
final AlertMessageBox messageBox = new AlertMessageBox(UIMessages.INSTANCE.warning(),
UIMessages.INSTANCE.w3wErrorText());
messageBox.show();
}
public void onSuccess(final String response) {
finishProgressBar();
if (response.isEmpty()) {
showException(UIMessages.INSTANCE.w3wErrorText());
return;
}
final JSONValue jsonValue = JSONParser.parseLenient(response);
final JSONObject jsonObject = jsonValue.isObject();
if (jsonObject.containsKey("geometry")) {
final JSONObject jsonCoords = jsonObject.get("geometry").isObject();
final double latitud = jsonCoords.get("lat").isNumber().doubleValue();
final double longitud = jsonCoords.get("lng").isNumber().doubleValue();
updateMap(latitud, longitud, 20, "EPSG:4326");
final LonLat lonLat = new LonLat(longitud, latitud);
transformToInternalProjection(lonLat, "EPSG:4326");
w3wTool.addElementToW3wLayer(lonLat, words);
} else if (jsonObject.containsKey("error")) {
showException(UIMessages.INSTANCE.fail() + jsonObject.get("message").toString());
} else {
showException(UIMessages.INSTANCE.w3wErrorText());
}
}
});
}
示例20
public void setValue(final String json) {
final JSONValue tree = JSONParser.parseStrict(json);
clear();
display(2, this, tree);
}