当前位置: 首页>>代码示例>>Java>>正文


Java JSONParser类代码示例

本文整理汇总了Java中com.google.gwt.json.client.JSONParser的典型用法代码示例。如果您正苦于以下问题:Java JSONParser类的具体用法?Java JSONParser怎么用?Java JSONParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JSONParser类属于com.google.gwt.json.client包,在下文中一共展示了JSONParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toList

import com.google.gwt.json.client.JSONParser; //导入依赖的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;
  }
 
开发者ID:eclipse,项目名称:che-archetypes,代码行数:20,代码来源:StringListUnmarshaller.java

示例2: getStyle

import com.google.gwt.json.client.JSONParser; //导入依赖的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;
}
 
开发者ID:geowe,项目名称:sig-seguimiento-vehiculos,代码行数:25,代码来源:LeafletStyle.java

示例3: extractFormName

import com.google.gwt.json.client.JSONParser; //导入依赖的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";
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:18,代码来源:WaitForBuildResultCommand.java

示例4: parseGadgetInfoJson

import com.google.gwt.json.client.JSONParser; //导入依赖的package包/类
@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;
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:17,代码来源:GwtGadgetInfoParser.java

示例5: getJsonErrorMessage

import com.google.gwt.json.client.JSONParser; //导入依赖的package包/类
/**
 * @param str String representation of a serialized JSON Exception
 * @return the value of the 'errorMessage' key
 */
public static String getJsonErrorMessage(String str) {
    try {
        JSONObject exc = JSONParser.parseStrict(str).isObject();
        if (exc != null && exc.containsKey("errorMessage")) {
            return retrieveErrorMessage(exc);
        } else if (exc != null && exc.containsKey("exception")) {
            JSONObject nestedExc = exc.get("exception").isObject();
            return retrieveErrorMessage(nestedExc);
        }
    } catch (Exception e) {
        if (str != null) {
            return str;
        } else {
            return "<no reason>";
        }
    }
    return null;
}
 
开发者ID:ow2-proactive,项目名称:scheduling-portal,代码行数:23,代码来源:JSONUtils.java

示例6: fetchNodesLimit

import com.google.gwt.json.client.JSONParser; //导入依赖的package包/类
private void fetchNodesLimit() {
    this.rm.getState(LoginModel.getInstance().getSessionId(), new AsyncCallback<String>() {
        public void onSuccess(String result) {
            // Parse json response to extract the current node limit
            JSONObject rmState = JSONParser.parseStrict(result).isObject();
            if (rmState == null) {
                LogModel.getInstance().logMessage("Failed to parse json rmState: " + result);
            } else {
                JSONValue maxNumberOfNodes = rmState.get("maxNumberOfNodes");
                if (maxNumberOfNodes != null && maxNumberOfNodes.isNumber() != null) {
                    model.setMaxNumberOfNodes(Long.parseLong(maxNumberOfNodes.isNumber().toString()));
                }
            }
        }

        public void onFailure(Throwable caught) {
            LogModel.getInstance()
                    .logMessage("Failed to access node limit through rmState: " + caught.getMessage());
        }
    });
}
 
开发者ID:ow2-proactive,项目名称:scheduling-portal,代码行数:22,代码来源:RMController.java

示例7: toMap

import com.google.gwt.json.client.JSONParser; //导入依赖的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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:JsonHelper.java

示例8: toMapOfLists

import com.google.gwt.json.client.JSONParser; //导入依赖的package包/类
public static Map<String, List<String>> toMapOfLists(String jsonStr) {
  Map<String, List<String>> map = new HashMap<>();

  JSONValue parsed = JSONParser.parseStrict(jsonStr);
  JSONObject jsonObj = parsed.isObject();
  if (jsonObj != null) {
    for (String key : jsonObj.keySet()) {
      JSONValue jsonValue = jsonObj.get(key);
      JSONArray jsonArray = jsonValue.isArray();

      List<String> values = new ArrayList<>();
      for (int i = 0; i < jsonArray.size(); i++) {
        values.add(jsonArray.get(i).isString().stringValue());
      }
      map.put(key, values);
    }
  }

  return map;
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:JsonHelper.java

示例9: parseJsonEvent

import com.google.gwt.json.client.JSONParser; //导入依赖的package包/类
private static ServerEvent parseJsonEvent(String msg) {
    try {
        JSONObject eventJ = JSONParser.parseStrict(msg).isObject();
        Name name = new Name(eventJ.get("name").isString().stringValue(), "");
        ServerEvent.Scope scope = ServerEvent.Scope.valueOf(eventJ.get("scope").isString().stringValue());
        ServerEvent.DataType dataType = eventJ.get("dataType") == null ? ServerEvent.DataType.STRING :
                ServerEvent.DataType.valueOf(eventJ.get("dataType").isString().stringValue());
        Serializable data;
        String from =  eventJ.get("from") == null ? null : eventJ.get("from").toString();
        if (dataType == ServerEvent.DataType.BG_STATUS) {
            data = BackgroundStatus.parse(eventJ.get("data").isString().stringValue());
        } else if (dataType == ServerEvent.DataType.JSON) {
            data = eventJ.get("data").isObject().toString();
        } else {
            data = eventJ.get("data").isString().stringValue();
        }
        ServerEvent sEvent = new ServerEvent(name, scope, dataType, data);
        sEvent.setFrom(from);
        return sEvent;

    } catch (Exception e) {
        GwtUtil.getClientLogger().log(Level.WARNING, "Unable to parse json message into ServerEvent: " + msg, e);
        return null;
    }
}
 
开发者ID:lsst,项目名称:firefly,代码行数:26,代码来源:ClientEventQueue.java

示例10: deserialize

import com.google.gwt.json.client.JSONParser; //导入依赖的package包/类
@Override
public Object deserialize(String payload, Type expected)
    throws SerializerException {

    JSONValue jsonValue = JSONParser.parseStrict(payload);

    try {
        Object object = fromJSONValue(jsonValue, expected);

        if (object == null) {
            throw new SerializerException(
                SerializerException.Error.NOT_DESERIALIZABLE);
        }

        return object;

    } catch (NoSuitableSerializableFactory exception) {
        throw new SerializerException(
            SerializerException.Error.NOT_DESERIALIZABLE, exception);
    }
}
 
开发者ID:snogaraleal,项目名称:wbi,代码行数:22,代码来源:JSONSerializer.java

示例11: deserialize

import com.google.gwt.json.client.JSONParser; //导入依赖的package包/类
@Override
public CallResponse deserialize(String payload) throws InvalidPayload {
    JSONArray array = JSONParser.parseStrict(payload).isArray();

    if (array.size() != CallResponse.Message.SIZE) {
        throw new InvalidPayload();
    }

    JSONString token = array.get(
        CallResponse.Message.POSITION_TOKEN).isString();
    JSONBoolean success = array.get(
        CallResponse.Message.POSITION_SUCCESS).isBoolean();
    JSONString returnValue = array.get(
        CallResponse.Message.POSITION_RETURN_VALUE).isString();

    return new CallResponse(
        token.stringValue(),
        success.booleanValue(),
        returnValue.stringValue());
}
 
开发者ID:snogaraleal,项目名称:wbi,代码行数:21,代码来源:DefaultCallResponseClientSerializer.java

示例12: parseMap

import com.google.gwt.json.client.JSONParser; //导入依赖的package包/类
public static <T extends Enum<T>> Map<T, Double> parseMap(Class<T> clazz,
		String text) {
	
	if (text == null) {
		return new TreeMap<T, Double>();
	} else {
	
		JSONValue v = JSONParser.parseLenient(text);
		Map<String, String> smap = JsonUtil.parseMap(v);

		Map<T, Double> map = new TreeMap<T, Double>();

		for (Map.Entry<String, String> e : smap.entrySet()) {
			T type = Enum.valueOf(clazz, e.getKey());
			Double d = Double.parseDouble(e.getValue());
			
			map.put(type, d);
		}

		return map;
	}
}
 
开发者ID:dawg6,项目名称:dhcalc,代码行数:23,代码来源:JsonUtil.java

示例13: setRequestBodyText

import com.google.gwt.json.client.JSONParser; //导入依赖的package包/类
/**
 * Sets the text of the currently selected editor to the value provided.
 *
 * @param value Json or free-form text that should be used to populate the form.
 */
public void setRequestBodyText(String value) {
  if (selectedEditor == BodyEditor.SCHEMA) {
    try {
      schemaForm.setJSONValue(JSONParser.parseStrict(value));
    } catch (Exception e) {
      showEditor(BodyEditor.FREEFORM, /* Do not focus on this content fill. */ false);
    }
  }

  // This may have been the original selection, or it may have been switched to by a json parsing
  // error or an error when assigning the json to the schema editor.
  if (selectedEditor == BodyEditor.FREEFORM) {
    requestBody.setText(value);
  }
}
 
开发者ID:showlowtech,项目名称:google-apis-explorer,代码行数:21,代码来源:RequestBodyForm.java

示例14: testRequredNotDuplicated

import com.google.gwt.json.client.JSONParser; //导入依赖的package包/类
public void testRequredNotDuplicated() {
  Schema lockedString = CustomSchema.lockedStringField(null);
  Map<String, Schema> properties = ImmutableMap.of("prop1", lockedString);
  ObjectSchemaEditor objectEditor =
      new ObjectSchemaEditor(schemaForm, null, null, properties, null, false);

  // Initialize a value for this property
  objectEditor.setJSONValue(JSONParser.parseStrict("{\"prop1\": \"a value\"}"));

  assertEquals(1, objectEditor.editors.size());
  assertEquals(ImmutableSet.of("prop1"), objectEditor.editors.keySet());
  assertEquals(ObjectElement.class, objectEditor.editors.get("prop1").getClass());
  assertEquals(StringSchemaEditor.class,
      ((ObjectElement) objectEditor.editors.get("prop1")).innerEditor.getClass());
  assertEquals("\"a value\"", objectEditor.editors.get("prop1").getJSONValue().toString());
}
 
开发者ID:showlowtech,项目名称:google-apis-explorer,代码行数:17,代码来源:ObjectSchemaEditorGwtTest.java

示例15: init

import com.google.gwt.json.client.JSONParser; //导入依赖的package包/类
public void init() {
	// try to get the serialized representation of the SQLite DB from the
	// local storage
	String serializedDb = storage.getItem(LOCALSTORAGE_KEY_DB);

	if (serializedDb == null || serializedDb.isEmpty()) {
		// if nothing is found, we create the database from scratch
		sqlDb = SQLite.create();

		// and inject the SQL file which creates the tables structure
		DbSchema dbSchema = (DbSchema) GWT.create(DbSchema.class);
		sqlDb.execute(dbSchema.sqlForSchema().getText());
	} else {
		// if the local storage already contains some data, parse it as a
		// JSON integer array
		JSONValue dbContent = JSONParser.parseStrict(serializedDb);

		// and initialize SQLite with this "file"
		sqlDb = SQLite.create(dbContent.isArray().getJavaScriptObject()
				.<JsArrayInteger> cast());
	}

	persistDB();
	getMinIdPasswd();
	getMinIdField();
}
 
开发者ID:guiguib,项目名称:yaph,代码行数:27,代码来源:DataAccess.java


注:本文中的com.google.gwt.json.client.JSONParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。