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


Java JsonObject.keySet方法代码示例

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


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

示例1: verifyOrder

import javax.json.JsonObject; //导入方法依赖的package包/类
/**
 * Verify node order
 */
private void verifyOrder(String parentUrl, String[] names)
        throws IOException {
    // check that nodes appear in creation order in their parent's list of children
    final String content = getContent(parentUrl + ".1.json", CONTENT_TYPE_JSON);
    String expected = "";
    for (String n: names) {
        expected +=n + ",";
    }
    //assertJavascript(expected, content, TEST_SCRIPT);
    try {
        String actual = "";
        JsonObject obj = JsonUtil.parseObject(content);
        
        for (String name : obj.keySet()) {
            Object o = obj.get(name);
            if (o instanceof JsonObject) {
                actual += name + ",";
            }
        }
        assertEquals(expected, actual);
    } catch (JsonException e) {
        throw new IOException(e.toString());
    }
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:28,代码来源:PostServletOrderTest.java

示例2: addCsource

import javax.json.JsonObject; //导入方法依赖的package包/类
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response addCsource(String jsonPayload) {
    JsonReader reader = Json.createReader(new StringReader(jsonPayload));

    JsonObject obj = reader.readObject();

    JsonObjectBuilder builder = Json.createObjectBuilder();

    builder.add("id", obj.getString("id"));
    builder.add("type", obj.getString("type"));

    for(String key:obj.keySet()) {
        if (!key.equals("id") && !key.equals("type")) {
            JsonObjectBuilder valueBuilder = Json.createObjectBuilder();
            valueBuilder.add("value", obj.get(key));
            if (key.equals("location")) {
                valueBuilder.add("type", "geo:json");
            }
            builder.add(key, valueBuilder.build());
        }
    }

    NgsiClient client = new NgsiClient(Configuration.ORION_BROKER);

    return client.createEntity(builder.build());
}
 
开发者ID:Fiware,项目名称:NGSI-LD_Wrapper,代码行数:28,代码来源:CsourceResource.java

示例3: createJsonBuilder

import javax.json.JsonObject; //导入方法依赖的package包/类
/** Allow for a JsonObject to be modified */
public JsonObjectBuilder createJsonBuilder(JsonObject source) {
  JsonObjectBuilder builder = Json.createObjectBuilder();
  for (String key : source.keySet()) {
    builder.add(key, source.get(key));
  }
  return builder;
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:9,代码来源:UserResource.java

示例4: getRatings

import javax.json.JsonObject; //导入方法依赖的package包/类
private JsonObject getRatings(Cookie user, String xreq, String xtraceid, String xspanid,
                              String xparentspanid, String xsampled, String xflags, String xotspan){
  ClientBuilder cb = ClientBuilder.newBuilder();
  String timeout = star_color.equals("black") ? "10000" : "2500";
  cb.property("com.ibm.ws.jaxrs.client.connection.timeout", timeout);
  cb.property("com.ibm.ws.jaxrs.client.receive.timeout", timeout);
  Client client = cb.build();
  WebTarget ratingsTarget = client.target(ratings_service);
  Invocation.Builder builder = ratingsTarget.request(MediaType.APPLICATION_JSON);
  if(xreq!=null) {
    builder.header("x-request-id",xreq);
  }
  if(xtraceid!=null) {
    builder.header("x-b3-traceid",xtraceid);
  }
  if(xspanid!=null) {
    builder.header("x-b3-spanid",xspanid);
  }
  if(xparentspanid!=null) {
    builder.header("x-b3-parentspanid",xparentspanid);
  }
  if(xsampled!=null) {
    builder.header("x-b3-sampled",xsampled);
  }
  if(xflags!=null) {
    builder.header("x-b3-flags",xflags);
  }
  if(xotspan!=null) {
    builder.header("x-ot-span-context",xotspan);
  }
  if(user!=null) {
    builder.cookie(user);
  }
  Response r = builder.get();
  int statusCode = r.getStatusInfo().getStatusCode();
  if (statusCode == Response.Status.OK.getStatusCode() ) {
    StringReader stringReader = new StringReader(r.readEntity(String.class));
    try (JsonReader jsonReader = Json.createReader(stringReader)) {
       JsonObject j = jsonReader.readObject();
       JsonObjectBuilder jb = Json.createObjectBuilder();
       for(String key : j.keySet()){
         int count = j.getInt(key);
         String stars = "<font color=\""+ star_color +"\">";
         for(int i=0; i<count; i++){
           stars += "<span class=\"glyphicon glyphicon-star\"></span>";
         }
         stars += "</font>";
         if(count<5){
           for(int i=0; i<(5-count); i++){
             stars += "<span class=\"glyphicon glyphicon-star-empty\"></span>";
           }
         }
         jb.add(key,stars);
       }
       JsonObject result = jb.build();
       return result;
    }
  }else{
    System.out.println("Error: unable to contact "+ratings_service+" got status of "+statusCode);
    return null;
  }
}
 
开发者ID:IBM,项目名称:microservices-traffic-management-using-istio,代码行数:63,代码来源:LibertyRestEndpoint.java

示例5: updateSensorData

import javax.json.JsonObject; //导入方法依赖的package包/类
public void updateSensorData(String data) {
    JsonObject list = Json.createReader(new StringReader(data)).readObject();
    for (String sId : list.keySet()) {
        Integer id = Integer.parseInt(sId);

        JsonObject sensObj = list.getJsonObject(sId);
        String sType = sensObj.getString("type");
        SensorType type = SensorType.getByType(sType);

        if (type != null) {
            // only supported types

            Sensor<?> sensor = sensorMap.get(id);
            boolean isNew = false;
            if (sensor == null) {
                // create it
                String uniqueID = sensObj.getString("uniqueid");
                sensor = createSensor(id, uniqueID, type);
                isNew = true;
            }

            if (sensor != null) {
                try {
                    sensor.updateSensor(sensObj);
                    if (isNew) {
                        addSensor(sensor);
                    }

                    // database save
                    Long entryId = createSensorDataEntry(sensor);
                    if (entryId != null) {
                        sensor.saveCurrentValueInDB(entryId);
                    }
                } catch (UpdateException ex) {
                    LOG.error("Error updating sensor data", ex);
                }
            }

        }

    }
}
 
开发者ID:dainesch,项目名称:HueSense,代码行数:43,代码来源:DataStore.java


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