本文整理汇总了Java中com.google.gwt.json.client.JSONValue.toString方法的典型用法代码示例。如果您正苦于以下问题:Java JSONValue.toString方法的具体用法?Java JSONValue.toString怎么用?Java JSONValue.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gwt.json.client.JSONValue
的用法示例。
在下文中一共展示了JSONValue.toString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toList
import com.google.gwt.json.client.JSONValue; //导入方法依赖的package包/类
public List<String> toList(String jsonStr) {
JSONValue parsed = JSONParser.parseStrict(jsonStr);
JSONArray jsonArray = parsed.isArray();
if (jsonArray == null) {
return Collections.emptyList();
}
List<String> list = new ArrayList<>();
for (int i = 0; i < jsonArray.size(); i++) {
JSONValue jsonValue = jsonArray.get(i);
JSONString jsonString = jsonValue.isString();
String stringValue = (jsonString == null) ? jsonValue.toString() : jsonString.stringValue();
list.add(stringValue);
}
return list;
}
示例2: getTagsFromJson
import com.google.gwt.json.client.JSONValue; //导入方法依赖的package包/类
/**
* @param arr list of tags as a JSON array
* @return the list of tags
*/
public static List<String> getTagsFromJson(String result) throws JSONException {
JSONValue val = parseJSON(result);
JSONArray arr = val.isArray();
if (arr == null) {
throw new JSONException("Expected JSON Array: " + val.toString());
}
List<String> tags = new ArrayList<String>(arr.size());
for (int i = 0; i < arr.size(); i++) {
tags.add(arr.get(i).isString().stringValue());
}
return tags;
}
示例3: getJobsFromJson
import com.google.gwt.json.client.JSONValue; //导入方法依赖的package包/类
private static Map<Integer, Job> getJobsFromJson(JSONValue value, JobsPaginationModel paginationModel)
throws JSONException {
Map<Integer, Job> jobs = new HashMap<>();
JSONObject jsonMain = getObject(value);
JSONValue jsonError = jsonMain.get("errors");
if (jsonError != null) {
throw new JSONException(jsonError.toString());
}
JSONObject jsonData = getObject(getProperty(jsonMain, "data"));
JSONObject jsonJobs = getObject(getProperty(jsonData, "jobs"));
long totalItems = getLongValue(jsonJobs, "totalCount");
JSONObject jsonPageInfo = getObject(getProperty(jsonJobs, "pageInfo"));
setPageInfoFromJson(jsonPageInfo, paginationModel, totalItems);
JSONArray jsonEdges = getArray(getProperty(jsonJobs, "edges"));
for (int i = 0; i < jsonEdges.size(); i++) {
JSONObject jsonJob = jsonEdges.get(i).isObject();
Job j = Job.parseJson(jsonJob);
jobs.put(j.getId(), j);
}
return jobs;
}
示例4: toMap
import com.google.gwt.json.client.JSONValue; //导入方法依赖的package包/类
public static Map<String, String> toMap(String jsonStr) {
Map<String, String> map = new HashMap<String, String>();
JSONValue parsed = JSONParser.parseStrict(jsonStr);
JSONObject jsonObj = parsed.isObject();
if (jsonObj != null) {
for (String key : jsonObj.keySet()) {
JSONValue jsonValue = jsonObj.get(key);
JSONString jsonString = jsonValue.isString();
// if the json value is a string, set the unescaped value, else set the json representation
// of the value
String stringValue = (jsonString == null) ? jsonValue.toString() : jsonString.stringValue();
map.put(key, stringValue);
}
}
return map;
}
示例5: serialize
import com.google.gwt.json.client.JSONValue; //导入方法依赖的package包/类
@Override
public String serialize(Object object) throws SerializerException {
if (!Utils.isSerializationCapable(object)) {
throw new SerializerException(
SerializerException.Error.NOT_SERIALIZABLE);
}
JSONValue jsonValue = toJSONValue(object);
if (jsonValue == null) {
throw new SerializerException(
SerializerException.Error.NOT_SERIALIZABLE);
}
return jsonValue.toString();
}
示例6: setJSONValue
import com.google.gwt.json.client.JSONValue; //导入方法依赖的package包/类
@Override
public void setJSONValue(JSONValue value) {
JSONArray arr = value.isArray();
if (arr != null) {
for (int i = 0; i < arr.size(); i++) {
// We may have to create additional editors
if (i >= editors.size()) {
addItem();
}
SchemaEditor editor = editors.get(i);
editor.setJSONValue(arr.get(i));
}
} else {
throw new JSONException("Not a valid JSON array: " + value.toString());
}
}
示例7: getObject
import com.google.gwt.json.client.JSONValue; //导入方法依赖的package包/类
private static JSONObject getObject(JSONValue value) throws JSONException {
JSONObject jsonObject = value.isObject();
if (jsonObject == null) {
throw new JSONException("Expected JSON Object: " + value.toString());
}
return jsonObject;
}
示例8: getArray
import com.google.gwt.json.client.JSONValue; //导入方法依赖的package包/类
private static JSONArray getArray(JSONValue value) throws JSONException {
JSONArray arr = value.isArray();
if (arr == null) {
throw new JSONException("Expected JSON Array: " + value.toString());
}
return arr;
}
示例9: getString
import com.google.gwt.json.client.JSONValue; //导入方法依赖的package包/类
private static String getString(JSONValue value) throws JSONException {
if (value.isNull() != null) {
return null;
}
JSONString string = value.isString();
if (string == null) {
throw new JSONException("Expected JSON String: " + value.toString());
}
return string.stringValue();
}
示例10: getLongValue
import com.google.gwt.json.client.JSONValue; //导入方法依赖的package包/类
private static long getLongValue(JSONObject obj, String fieldName) throws JSONException {
JSONValue jsonLongValue = obj.get(fieldName);
if (jsonLongValue == null) {
throw new JSONException("Expected JSON Object with attribute " + fieldName + ": " + obj.toString());
}
JSONNumber jsonLong = jsonLongValue.isNumber();
if (jsonLong == null) {
throw new JSONException("Expected JSON number: " + jsonLongValue.toString());
}
return (long) jsonLong.doubleValue();
}
示例11: create
import com.google.gwt.json.client.JSONValue; //导入方法依赖的package包/类
/**
* Creates one of implementations of {@link EditorPropertyWidget}.
*
* @return an instance of {@link EditorPropertyWidget}
*/
public EditorPropertyWidget create(@NotNull String propertyName, @NotNull JSONValue value) {
if (value.isBoolean() != null) {
return new EditorBooleanPropertyWidget(propertyName, value.isBoolean().booleanValue());
}
if (value.isNumber() != null) {
Double doubleValue = value.isNumber().doubleValue();
return new EditorNumberPropertyWidget(propertyName, doubleValue.intValue());
}
return new EditorStringPropertyWidget(propertyName, value.toString());
}
示例12: setJSONValue
import com.google.gwt.json.client.JSONValue; //导入方法依赖的package包/类
@Override
public void setJSONValue(JSONValue value) {
JSONString stringVal = value.isString();
if (stringVal != null) {
hasText.setText(stringVal.stringValue());
} else {
throw new JSONException("Not a valid JSON string: " + value.toString());
}
}
示例13: deserialize
import com.google.gwt.json.client.JSONValue; //导入方法依赖的package包/类
public EmpiriaState deserialize(JSONValue stateJson) {
JSONObject stateObject = stateJson.isObject();
if (isNewStateObject(stateJson)) {
EmpiriaStateType type = getStateType(stateObject);
String state = stateObject.get(EmpiriaState.STATE).isString().stringValue();
return new EmpiriaState(type, state, getSavedLessonIdentifier(stateObject));
}
return new EmpiriaState(EmpiriaStateType.OLD, stateJson.toString(), StringUtils.EMPTY);
}