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


Java JsonObject.getAsJsonPrimitive方法代码示例

本文整理汇总了Java中com.google.gson.JsonObject.getAsJsonPrimitive方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObject.getAsJsonPrimitive方法的具体用法?Java JsonObject.getAsJsonPrimitive怎么用?Java JsonObject.getAsJsonPrimitive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gson.JsonObject的用法示例。


在下文中一共展示了JsonObject.getAsJsonPrimitive方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: update

import com.google.gson.JsonObject; //导入方法依赖的package包/类
private void update() {
	try {
		URLConnection conn = new URL(url).openConnection();
		conn.setConnectTimeout(10000);
		conn.setReadTimeout(10000);
		String json = "";
		try (BufferedReader reader = new BufferedReader(
				new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) {
			json = reader.lines().collect(Collectors.joining("\n"));
		}
		json = json.trim().replaceAll("\\[", "").replaceAll("\\]", ""); //quick and dirty fix
		
		JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);
		JsonPrimitive priceDollars = jsonObject.getAsJsonPrimitive("price_usd");
		
		price = priceDollars.getAsString();
		int maxIndex = price.indexOf(".") + 3;
		if (price.length() >= maxIndex)
			price = price.substring(0, maxIndex);
	} catch (Exception e) {
		e.printStackTrace();
		price = "0.00";
	}
	price = "{\"price\":\"" + price + "\"}";
}
 
开发者ID:thehen101,项目名称:RainServer,代码行数:26,代码来源:CommandPrice.java

示例2: Parameter

import com.google.gson.JsonObject; //导入方法依赖的package包/类
public Parameter(JsonObject param) {
    try {
        setNameAndType(param.get("name").getAsString(), param.get("type").getAsString());
        if(param.get("value").isJsonObject()){
            setJsonContent(param.getAsJsonObject("value"));
        } else {
            JsonPrimitive value = param.getAsJsonPrimitive("value");
            if(value.isString()) {
                setStringContent(value.getAsString());
            } else if(value.isNumber()) {
                setDoubleContent(value.getAsDouble());
            } else if(value.isBoolean()) {
                setBooleanContent(value.getAsBoolean());
            }
        }
    } catch (Exception e){
        throw new IllegalArgumentException("invalid parameter structure");
    }
}
 
开发者ID:DesktopRemoteManagement,项目名称:DRM-Desktop,代码行数:20,代码来源:Parameter.java

示例3: decryptCardCode

import com.google.gson.JsonObject; //导入方法依赖的package包/类
/**
 * 卡券Code解码
 *
 * @param encryptCode 加密Code,通过JSSDK的chooseCard接口获得
 * @return 解密后的Code
 */
@Override
public String decryptCardCode(String encryptCode) throws WxErrorException {
  String url = "https://api.weixin.qq.com/card/code/decrypt";
  JsonObject param = new JsonObject();
  param.addProperty("encrypt_code", encryptCode);
  String responseContent = this.wxMpService.post(url, param.toString());
  JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
  JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
  JsonPrimitive jsonPrimitive = tmpJsonObject.getAsJsonPrimitive("code");
  return jsonPrimitive.getAsString();
}
 
开发者ID:11590692,项目名称:Wechat-Group,代码行数:18,代码来源:WxMpCardServiceImpl.java

示例4: parse

import com.google.gson.JsonObject; //导入方法依赖的package包/类
private void parse(final StringBuilder buffer, final String message) {
    final JsonParser parser = new JsonParser();
    try {
        final JsonElement element = parser.parse(new StringReader(message));
        if(element.isJsonObject()) {
            final JsonObject json = element.getAsJsonObject();
            final JsonObject error = json.getAsJsonObject("error");
            if(null == error) {
                this.append(buffer, message);
            }
            else {
                final JsonPrimitive tag = error.getAsJsonPrimitive(".tag");
                if(null == tag) {
                    this.append(buffer, message);
                }
                else {
                    this.append(buffer, StringUtils.replace(tag.getAsString(), "_", " "));
                }
            }
        }
        if(element.isJsonPrimitive()) {
            this.append(buffer, element.getAsString());
        }
    }
    catch(JsonParseException e) {
        // Ignore
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:29,代码来源:DropboxExceptionMappingService.java

示例5: execute

import com.google.gson.JsonObject; //导入方法依赖的package包/类
public void execute() throws IOException, URISyntaxException, AuthenticationException {
      JsonObject responseJson = new JsonObject();
      WorkItemMover mover = new WorkItemMover(parentService);
      boolean isMoved = false;
      boolean previewOnly = false;
      Collection<AttributeDefinition> moveResults = null;

      // read request data
      JsonObject workItemData = RequestReader.readAsJson(request);
      JsonPrimitive previewPrimitive = workItemData.getAsJsonPrimitive("previewOnly");
      JsonPrimitive targetPA = workItemData.getAsJsonPrimitive("targetProjectArea");
      JsonArray workItemJson = workItemData.getAsJsonArray("workItems");
      JsonArray typeMappingJson = workItemData.getAsJsonArray("typeMapping");
      JsonArray attributesJson = workItemData.getAsJsonArray("mapping");

      if(previewPrimitive != null) {
          previewOnly = previewPrimitive.getAsBoolean();
      }
      // map cient data to model
      Collection<Integer> clientWorkItemList = gson.fromJson(workItemJson, workItemIdCollectionType);
      Collection<AttributeDefinition> clientMappingDefinitions = gson.fromJson(attributesJson, attributesCollectionType);
      Collection<TypeMappingEntry> typeMappingDefinitions = gson.fromJson(typeMappingJson, typeMappingCollectionType);
      Map<String, String> typeMap = new HashMap<String, String>();
      for (TypeMappingEntry def : typeMappingDefinitions) {
          typeMap.put(def.getSource(), def.getTarget());
      }

      try {
          // fetch full work item information
	List<IWorkItem> items = WorkItemHelpers.fetchWorkItems(clientWorkItemList, workItemServer, monitor);

          // resolve project area
          IProjectAreaHandle targetArea = ProjectAreaHelpers.getProjectArea(targetPA.getAsString(), parentService);

          // prepare movement and track fields to be changed
	MovePreparationResult preparationResult = mover.PrepareMove(items, targetArea, clientMappingDefinitions, typeMap);

	// store attribute based ovservations to be able to return this information to the end user
	moveResults = preparationResult.getAttributeDefinitions().getAttributeDefinitionCollection();

	if(!previewOnly) {
              // try to move the work items...
              IStatus status = mover.MoveAll(preparationResult.getWorkItems());
              isMoved = status.isOK();
          }
} catch (Exception e) {
          // Inform the user the the items could not be moved
          responseJson.addProperty("error", e.getMessage());
}

      // prepare data to be returend
      responseJson.addProperty("successful", isMoved);
      responseJson.add("mapping", gson.toJsonTree(moveResults, resultsType));
      response.getWriter().write(gson.toJson(responseJson));
  }
 
开发者ID:jazz-community,项目名称:rtc-workitem-bulk-mover-service,代码行数:56,代码来源:MoveService.java


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